/ / PHP vārdu telpas problēmas ar iezīmēm - php, laravel, namespaces, laravel-5.1, īpašības

PHP vārdu telpas problēmas ar iezīmēm - php, laravel, namespaces, laravel-5.1, īpašības

Man šodien ir visdārgākā problēma, kad kaut kas vienmēr darbojas, kaut kādā veidā ir pārtraucis darbu. Varbūt tas ir viens no šiem stulba vienkāršiem jautājumiem, kurus es pārāk aklam redzēt.

Tātad, šeit notiekošais:

Man ir šāda faila struktūra (es tikai rādīju attiecīgos failus)

~/project
v app
v Models
User.php
v Support
v Traits
Sluggable.php
composer.json
composer.lock

User.php

<?php

namespace AppModels;

use IlluminateAuthAuthenticatable;
use IlluminateDatabaseEloquentModel;
use IlluminateAuthPasswordsCanResetPassword;
use IlluminateFoundationAuthAccessAuthorizable;
use IlluminateContractsAuthAuthenticatable as AuthenticatableContract;
use IlluminateContractsAuthAccessAuthorizable as AuthorizableContract;
use IlluminateContractsAuthCanResetPassword as CanResetPasswordContract;
use AppSupportTraitsSluggable;

class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
{
//////////////
//* Traits *//
//////////////
use Authenticatable, Authorizable, CanResetPassword, Sluggable;

////////////////////////
//* Model Attributes *//
////////////////////////
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ["name", "email", "password"];

/**
* The attributes excluded from the model"s JSON form.
*
* @var array
*/
protected $hidden = ["password", "remember_token"];

/////////////////////
//* Boot Override *//
/////////////////////
/**
* Override the Boot Method to schedule tasks that are Event-Triggered.
*
* @return void
*/
public static function boot()
{
// Call the Parent Method
parent::boot();

// Intercept the "Created" Event
static::creating(function($user)
{
// Assign a Validation Token
$user->validation_token = str_slug(str_random(64));

// Initialize the Slug for the User
$user->slug = $user->makeSlug();
});
}

////////////////////////////
//* Attributes Overrides *//
////////////////////////////
/**
* Overrides the $user->name Attibute to update the Sluggable Name.
*
* @return void
*/
public function setNameAttribute($name)
{
$this->attributes["name"] = $name;

$this->attributes["slug"] = $this->makeSlug();
}
}

Traits.php

<?php

namespace AppSupportTraits;

trait Sluggable
{
/**
* The Name of the Attribute that determines the Slug.
*
* Use $this->$sluggableAttribute to determine the Sluggable Value.
*
* @var string
*/
protected $sluggableAttribute = "name";

/**
* The Name of the Attribute that contains the Slug.
*
* Use $this->$slugAttribute to determine the Slug Value.
*
* @var string
*/
protected $slugAttribute = "slug";

/**
* Generates a Slug based on the Sluggable Attribute.
*
* @return string
*/
public function makeSlug()
{
// Intialize the Slug
$this->$slugAttribute = str_slug($this->$sluggableAttribute);

// Check for an existing Slug
$slug = $this->whereRaw("{$this->slugAttribute} RLIKE "^{$this->$sluggableAttribute}(-[0-9]+)?$"")
->latest($timestamps ? UPDATED_AT : $this->primaryKey) // Find the Latest Slug
->pluck($this->slugAttribute); // Only grab the Slug Attribute

// See if a Slug was Found
if($slug)
{
// Determine the new Slug Identifier
$slugID = intval(end(explode("-", $slug))) + 1;

// Reassign a new Slug
$this->$slugAttribute .= "-" . $slugID;
}

return $this->$slugAttribute;
}
}

Un es nonāku pie kļūmes:

FatalErrorException in User.php line 19:
Trait "AppSupportTraitsSluggable" not found

Un man nav ne jausmas, kāpēc.


Ja tas ir svarīgi, es izmantoju Laravel 5.1 kā manu sistēmu.

Rediģēt:

Šeit ir composer.json failu gadījumā, ja tas ir svarīgi:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"illuminate/html": "^5.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\": "app/"
},
"files": [
"app/Helpers/route.php"
]
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r "copy(".env.example", ".env");""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}

Atbildes:

0 atbildei Nr. 1

Pēc papildu analīzes es atklāju šo jautājumu un noteikti bija viens no šiem stulba vienkāršiem jautājumiem, ka es esmu pārāk neredzīgs, lai to aplūkotu.

Vienkārši sakot, Sluggable.php fails trūka .php pagarinājums Es domāju, ka es tik ļoti izmantoju, lai redzētu failu nosaukumus bez paplašinājumiem, kurus es neievēroju.


Saistītie jautājumi


Komentāri (0)

Pievieno komentāru