Я провожу, как 4 часа, выясняя это, но я не могу его решить. Я использую laravel 5.1laravel 5.1 не найден
Я хочу посмотреть владельца организации или наоборот, осмотреть организации, в которых пользователь является владельцем.
Я reciving следующее сообщение об ошибке от моего веб-сервера:
FatalErrorException in Model.php line 893:
Class 'app\models\Organisation' not found
in Model.php line 893
at FatalErrorException->__construct() in HandleExceptions.php line 133
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 118
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at Model->hasMany() in User.php line 19
at User->owner_of() in TestController.php line 24
at TestController->index() in Controller.php line 256
at call_user_func_array:{/home/shifts/public_html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:256}() in Controller.php line 256
at Controller->callAction() in ControllerDispatcher.php line 164
at ControllerDispatcher->call() in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}() in Pipeline.php line 139
Моя структура папок следующим образом:
- App/
-- Models/
--- Organisation.php
--- User.php
пользователя Модель
<?php
namespace app\models;
use Illuminate\Database\Eloquent\Model;
class User extends Model {
protected $table = 'users';
public $timestamps = true;
public function owner_of()
{
return $this->hasMany('Organisation', 'owner_id');
}
}
Организация Модель
<?php
namespace app\models;
use Illuminate\Database\Eloquent\Model;
class Organisation extends Model {
protected $table = 'organisations';
public $timestamps = true;
public function owner()
{
return $this->belongsTo('App\Models\User','owner_id','id');
}
}
Controller Test (код я выполнение) схемы
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\Organisation;
use View;
use Debugbar;
class TestController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$site = url('test');
echo "testpage <a href=\"$site\">Reload</a>";
$u = User::find(1);
var_dump($u);
echo "<br /><br />";
var_dump($u->owner_of());
echo "<br /><br />";
$o = Organisation::find(1);
echo "<br /><br />";
var_dump($o);
echo "<br /><br />";
var_dump($o->owner());
}
}
пользователей
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UsersAccess extends Migration
{
public function up()
{
Schema::create('users_roles', function(Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('ex_id');
$table->string('obj',3);
$table->integer('granted');
$table->timestamps();
});
}
}
схема организации
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateOrganisationsTable extends Migration {
public function up()
{
Schema::create('organisations', function(Blueprint $table) {
$table->increments('id');
$table->integer('owner_id');
$table->string('name');
$table->text('description');
$table->timestamps();
$table->softDeletes();
});
}
}
Может кто-нибудь указать мне, что я делаю неправильно? Я смотрю на эту проблему. (это первый раз, когда я пытаюсь сделать проект в Laravel 5.x)
Попробуйте запустить 'composer dump-autoload' и посмотрите, не делает ли это трюк. – Bogdan
Я просто попробовал, что, к сожалению, он этого не решил – Thyvo