in local host i haven't this problem but in linux host in CPannel i receive this error
Class 'App\Service' not found
it's just an example i have same problem in some models..
my relations doesnt work properly in original host but in local host i haven't got any problem
my models:
<?php
namespace App;
use App\Category;
use App\Project;
use App\Service;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $fillable = [
'title', 'parent_id','title_en',
];
public function category(){
return $this->hasMany(Category::class,'parent_id');
}
public function parent(){
return $this->category('parent');
}
public function project(){
return $this->belongsToMany(project::class);
}
public function service(){
return $this->belongsToMany(service::class);
}
}
my controller :
namespace App\Http\Controllers;
use App\Service;
use Illuminate\Http\Request;
class ServiceController extends Controller
{
public function landpage(){
$services=Service::with('cat')->get();
return view('services.index',compact('services'));
}
public function detail($id){
$services=service::with('cat')->findOrFail($id);
return view('service_detail.index',compact('services'));
}
}
ok as i found .. the models are sensitive to capital words..
i changed all of the models to capital words..
App/service => App/Service
and it worked
Related
I updated a backpack project from backpack 4.0 to 4.1 and followed the upgrade guide that is provided on the backpack site. Laravel still runs on 6.x and has not been upgraded lately.
The list and /edit update views are working as intended. Only when trying to open a show view (happens on all models), then the following error occurs:
Too few arguments to function Illuminate\Database\Eloquent\Model::created(), 0 passed in /var/www/vendor/backpack/crud/src/app/Library/CrudPanel/CrudPanel.php on line 330 and exactly 1 expected
I tried to follow the stack trace but I can't find the source that throws the error. I also tried to remove all the methods from one model and just keep construct() and setup() and even then the errors is still thrown.
Edit: The error occurs for all models, this is the code of one random model.
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Vereine extends KVUser
{
}
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class KVUser extends Model
{
use CrudTrait;
use SoftDeletes;
protected $table = 'user';
public $incrementing = true;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $guarded = [];
public function __construct(array $attributes = [])
{
$this->creating([$this, 'onCreating']);
$this->updating([$this, 'onUpdating']);
parent::__construct($attributes);
}
public static function deleting($callback)
{
parent::deleting($callback);
$callback->update(['deleted' => 1]);
}
public function onCreating(\App\Models\KVUser $row)
{
// Placeholder for catching any exceptions
if (!\Auth::user()->id) {
return false;
}
$row->setAttribute('created_id', \Auth::user()->id);
}
public function onUpdating(\App\Models\KVUser $row)
{
// Placeholder for catching any exceptions
if (!\Auth::user()->id) {
return false;
}
$row->setAttribute('updated_id', \Auth::user()->id);
}
}
namespace App\Http\Controllers\Admin;
use App\Http\Requests\VereineRequest;
use App\Models\Vereine;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class VereineCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
public function __construct()
{
parent::__construct();
}
public function setup()
{
$this->crud->setModel('App\Models\Vereine');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/vereine');
$this->crud->setEntityNameStrings('Verein', 'Vereine');
$this->crud->setListView('vendor/backpack/crud/vereine/vereine_list');
$this->crud->setShowView('vendor/backpack/crud/vereine/vereine_show');
}
}
Screenshot Error Message
I would really appreciate some help - thank you!
For clearly to identify error you should attached image. Thanks
I'm working on the Excel exports in my laravel project. Now I get this error:Class 'App\Export\UsersExport' not found I made 3 others and they worked. This one doesn't and I can't seem to figure out what causes this error. I'm using "Maatwebsite's Laravel-Excel".
My exports controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//exports
use App\Export\UsersExport;
use App\Exports\StudyClassExport;
use App\Exports\EducationsExport;
use App\Exports\IntakesExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;
class ExportsController extends Controller
{
public function users()
{
return Excel::download(new UsersExport, 'gebruikers.xlsx');
}
public function educations()
{
return Excel::download(new EducationsExport, 'opleidingen.xlsx');
}
public function classes()
{
return Excel::download(new StudyClassExport, 'klassen.xlsx');
}
public function intakes()
{
return Excel::download(new IntakesExport, 'intakes.xlsx');
}
}
UsersExport:
<?php
namespace App\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class UsersExport implements FromCollection
{
/**
* #return \Illuminate\Support\Collection
*/
public function collection()
{
return User::all();
}
}
I have no idea what causes this error. The others work but this one doesn't
You have a typo:
use App\Export\UsersExport;
use App\Exports\UsersExport;
ExportS
I'm following the Laracasts series and have run into an issue on the episode Laravel 5.4 From Scratch: Route Model Binding.
Laravel version:
Laravel Framework 5.6.13
The error:
Class App\Http\Controllers\Panel does not exist
This shows on both the /panel and /panel/1 pages
App\Http\Controllers\PanelController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
// Code works if I uncomment below line, and change the show function to "show($panel)"
//use App;
class PanelController extends Controller
{
public function index()
{
$panels = Panel::all();
return view('panel/index', compact('panels'));
}
public function show(Panel $panel)
{
return $panel;
return view('panel/show', compact('panel'));
}
}
routes/web.php
// Main panel view
Route::get('/panel', 'PanelController#index');
// Individual panel view
Route::get('/panel/{panel}', 'PanelController#show');
App/Panel.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Panel extends Model
{
public static function activePanels()
{
return static::where('status', 1)->get();
}
}
Add this line in panel controller before the class
use App\Panel;
You need to add use App\Panel; to top of class
Or call it by full namespace $panels = App\Panel::all();
You don't included your model to class.
Add App\Panel to main include section:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Panel;
class PanelController extends Controller
{
public function index()
{
$panels = Panel::all();
return view('panel/index', compact('panels'));
}
public function show(Panel $panel)
{
return $panel;
return view('panel/show', compact('panel'));
}
}
or load model in your class method manually:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PanelController extends Controller
{
public function index()
{
$panels = App\Panel::all();
return view('panel/index', compact('panels'));
}
public function show(Panel $panel)
{
return $panel;
return view('panel/show', compact('panel'));
}
}
I'm wondering when to use the fully qualified class name or when to put a use statement on top of the class.
For example:
namespace App;
use Illuminate\Database\Eloquent\Model;
class ImageStatus extends Model {
public function image(): \Illuminate\Database\Eloquent\Relations\BelongsTo {
return $this->belongsTo( \App\Image::class, 'id' );
}
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo {
return $this->belongsTo( \App\User::class, 'id' );
}
}
At the moment I have this piece of code and my PHPStorm tells me Unnecessary fully qualified name. This hint disappears when I change it to:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ImageStatus extends Model {
public function image(): BelongsTo {
return $this->belongsTo( \App\Image::class, 'id' );
}
public function user(): BelongsTo {
return $this->belongsTo( \App\User::class, 'id' );
}
}
So I'm wondering what the difference is, performance wise, code readability and if one is better than the other.
When you do use SomeNamespace\ClassName than you do not have later append \SomeNamespace to ClassName. So your example should be
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ImageStatus extends Model {
public function image(): BelongsTo {
return $this->belongsTo(Image::class, 'id' );
}
public function user(): BelongsTo {
return $this->belongsTo(User::class, 'id' );
}
}
Please note that when you are in same namespace, than you do not need to add namespace to class name. When namespace App; then User::class instead of \App\User::class
namespace MyApp\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateAdminGroup extends FormRequest
{
public function authorize()
{
return false;
}
public function rules()
{
return [
//
];
}
}
My Controller:
namespace MyApp\Http\Controllers\Administration\Resource;
use MyApp\Http\Requests\Admin\Admin\CreateAdminGroup;
But i get an error that Class SwapSome\Http\Requests\Admin\Admin\CreateAdminGroup does not exist
Why do I get this error, the request is there, everything shuold be good.
My request in the App\Http\Requests\Admin\Admin\ folder
Thank you!
Change request's namespace to:
namespace MyApp\Http\Requests\Admin\Admin;