Getting issue "Class 'App/Category' not found" it - laravel-5

In Category.php
namespace App;
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
and in Controller.php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Setting;
use App\Post;
use function GuzzleHttp\Promise\all;
use Illuminate\Http\Request;
First Change from use App\Category; to use Category, to use \Category, to use App\Models\Category.
Second composer dump-autoload.

You are using two namespace in Category.php
namespace App; //REMOVE THIS If model file is in app\Models folder
namespace App\Models; // Remove this if model file is in app(root) folder
use Illuminate\Database\Eloquent\Model;
class Category extends Model {......}

Include it in your class dependencies:
use App\Category;

Related

Target class [FrontendController] does not exist

please help. I got this error "Target class [FrontendController] does not exist."
This is my route :
<?php
use Illuminate\Support\Facades\Route;
Route::get('/','FrontendController#home');
My Controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class FrontendController extends Controller
{
public function home()
{
return view ('index');
}
}
Why this happend? can anyone help me please? :(
You have to refer to the controller, you have 2 options
Laravel 7 and lower
Route::get('/','App\Http\Controllers\FrontendController#home');
If you are using Laravel 8 then you have to change the structure of the route
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home']);

Class videoThumbnail for found in laravel

i'm using pawlox/video-thumbnail but got error 'Class not Found'.
this is my Gallery controller
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use App\Gallery_model;
use App\Gallery_image_model;
use App\Search_index_model;
use DB;
use File;
use Storage;
use URL;
use Image;
use Mail;
use VideoThumbnail;
this is my config/app.php file
in providers array i do
Pawlox\VideoThumbnail\VideoThumbnailServiceProvider::class,
in aliases array i do
'VideoThumbnail' => Pawlox\VideoThumbnail\Facade\VideoThumbnail::class
i publish package config file also but still got error..

How to enable soft delete in laravel backpack

I'm doing CRUD operation using Backpack. Now I need soft delete for that. How can I enable it.
Following can be done for soft delete in Laravel.
add a column in the table called "deleted_at" with type datetime.
In the Model add namespace "use Illuminate\Database\Eloquent\SoftDeletes;" and Trait "use SoftDeletes;"
Example
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
class Age extends Model
{
use CrudTrait;
use SoftDeletes;

Class 'App\' not found on laravel 5.2

I want to add data to the database after a successful validation,but i get this error.'
FatalThrowableError in AboutController.php line 51:
Class 'App\About' not found.
My Controller
<?php
namespace App\Http\Controllers;
use App\About;
use Illuminate\Http\Request;
use App\Http\Requests;
class AboutController extends Controller
{
public function store(Request $request)
{
//
$about = $request->about;
$validation = \Validator::make($about, About::$rules);
if($validation->passes())
{
About::create($about);
return route('about/admin')->compact(about);
}
}
my Model
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
//
protected $guarded = array('id');
protected $fillable = array('about');
public static $rules = array('about' => 'required|5');
}
location of controllers and Model:
App\Http\Controllers\AboutController
App\About
I have tried to run
php artisan cache:clear
php artisan clear-compiled
composer dump-autoload
I'm stuck can anyone tell me what is causing this?
As #webNeat said you should change the namespace that you are using in your Model.
Your Model About
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
Controller
<?php
namespace App\Http\Controllers;
use App\About; // You have declared App\Http\Controllers in your Model
Model About Fixed
<?php
namespace App; // change to this namespace
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
If you're a bit lost with Laravel or namespaces I strongly recommend you to use php artisan with each of its commands, and see and study what they do by reading all the code generated. For this case with:
php artisan make:model About
You will get a fresh new About model prepared for receive all your code with the correct namespace.
changing the namespace of your model to App should fix the issue.
<?php
namespace App; // <- here
use Illuminate\Database\Eloquent\Model;
class About extends Model
{

Class with model could not be found in Lumen

In my web browser I am getting this error:
FatalErrorException in UserController.php line 18:
Class 'App\Report'
not found
It seems that UserControler.php page cannot find report.php page.
Here is my folder structure:
lumen
-api
--report.php // file where model Report is
---Http
----Controller
------UserController.php // file where i get error
-bootstrap
- ...
Header of UserController.php
namespace App\Http\Controllers;
use Illuminate\Database\Schema\Blueprint;
use App\Report; // it seems here is problem
use App\User; // with user model is same problem
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
class UserController extends Controller {
...
Header of report.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Report extends Model {
...
I am using Apache, Ubuntu, PHP 5.5 with Lumen framework
First of all model file name should be same as your class name here
lumen
-api
--report.php // This should be Report.php
---Http
----Controller
------UserController.php // file where i get error
-bootstrap
- ...
Also your Report.php Model will be under app directory same directory where your User Model resides

Resources