Laravel - Model Class not found
Laravel 5 promotes the use of namespaces for things like Models and Controllers. Your Model is under the App
namespace, so your code needs to call it like this:
Route::get('/posts', function(){
$results = \App\Post::all();
return $results;
});
As mentioned in the comments you can also use
or import a namespace in to a file so you don't need to quote the full path, like this:
use App\Post;
Route::get('/posts', function(){
$results = Post::all();
return $results;
});
While I'm doing a short primer on namespaces I might as well mention the ability to alias a class as well. Doing this means you can essentially rename your class just in the scope of one file, like this:
use App\Post as PostModel;
Route::get('/posts', function(){
$results = PostModel::all();
return $results;
});
More info on importing and aliasing namespaces here: http://php.net/manual/en/language.namespaces.importing.php
Laravel eloquent model Class not found
Top of your web.php route file mention model
use App\Task;
and then use
Route::get('/task',function(){
$task = App\Task::all();
return view('task',['task' => $task]);
});
Class Not Found on Laravel
You need to add the namespace. Replace Scifi
by App\Scifi
.
Laravel Model Class Cant Be Found In Routes
Try this
create model using command
php artisan make:model MenuList
App\Models\MenuList.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MenuList extends Model
{
use HasFactory;
public static function listData()
{
return [
'id' => 1,
'title' => 'liston one',
];
}
}
routes/web.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Models\MenuList;
Route::get('/', function () {
return view('listings', [
'heading' => 'lates listing',
'listings' => MenuList::listData()
]);
});
Related Topics
How to Use Array_Unique on an Array of Arrays
PHP Regex to Get String Inside Href Tag
Getting a PHP Pdo Connection from a MySQL_Connect()
How to Select Default Value of a Field
Backreference Does Not Work in PHP
Is MySQLi Extension Enabled in This PHP Configuration
Change the Date Format in Laravel View Page
How to Get the First Word of a Sentence in PHP
How to Enable --Enable-Soap in PHP on Linux
How to Convert Excel Xls to CSV Using PHP
Php: iPad Does Not Play Mp4 Videos Delivered by PHP, But If Accessed Directly It Does
Interface Implementation: Declaration Must Be Compatible
Concatenate Values of N Arrays in PHP
PHP on Godaddy Linux Shared Trying to Send Through Gmail Smtp
Warning: Date() Expects Parameter 2 to Be Long, String Given In