Why Suddenly Laravel started showing 'page not found' error? - php

I was working on my project and suddenly Laravel started showing Sorry, the page you are looking for could not be found. error. Here is how my web.php, CarController.php and view's location looks like.
web.php
Route::group(['middleware'=>'auth'],function(){
Route::get('cars/create',"CarController#create");
}
CarController.php
<?php
namespace App\Http\Controllers;
use App\Car;
use Illuminate\Http\Request;
use Auth;
class CarController extends Controller
{
public function create()
{
return view('cars.create');
}
}
View cars.create exist at /resources/views/cars/create.blade.php.
I don't know what caused this error but It's really irritating. I think this error came into existence because I had created one model named Request which might conflict with the actual Request class made by Laravel.
But, As soon as I saw the error, I deleted that Model including migration and controller. But still, the error is there. Any help would be appreciated!

Route::get('cars',"CarController#index");
Route::get('cars/{car}',"CarController#show");///remove this route definition or keep it at the end of your route file

Are you logged in ?? when you're trying to get the route??
usually what happens is the session expires after sometime.

Related

Laraver: I'm always getting this error when I call a controller in another controller: "Class 'CoreController' not found"

When I'm calling a controller in another controller in laravel 5.8 I'm always getting this error: "Class 'CoreController' not found" even though I called the use method "use CoreController;".
I checked many times for spelling errors and I even restarted apache to see if is a problem with my server but still no results.
An image about the problem to be more clear:
// This is the controller where I'm calling the "CoreController" I know kinda confusing names :P
namespace App\Http\Controllers;
use CoreController;
// The class
class PageController extends Controller
// the function
public function dashboard()
{
$core = new CoreController;
return view('pages.dashboard')->with('core', $core);
}
When you say
use XXXXXXController;
is a way of saying "From now on, every reference to XXXXXController must be found in \XXXXXController.
So, by including that line, you got exactly the opposite of what you wanted, because that CoreController class was already well mapped, until you included that line and said "Ok, forget the original mapping of CoreController, now go search CoreController to "\". Where, obviously, it was not.

Laravel 5.5: Controller does not exist

Coming from CodeIgniter, I decided that it's time for something new and went for Laravel. I love the syntax of the framework and how clean it is, however, I am overwhelmed by how complicated simple things seem to be. I have a controller and want to link to a function in said controller. Whatever I do, I keep getting this error:
ReflectionException in Route.php line 280:
Class App\Http\Controllers\TasksController does not exist
I have Googled this issue but I just can't seem to figure it out. It seems like I got everything right but then again, I'm completely new to this framework so I don't really know. I have a namespace, a route and all of that stuff. Anyway, here is my code:
The link
<a class="nav-link" href="<?= url('tasks') ?>">Tasks</a>
My route in routes.php
Route::resource('tasks', 'TasksController');
TasksController.php
<?php
namespace App\Http\Controllers\Controller;
use App\User;
use App\Http\Controllers\Controller;
class TasksController extends Controller
{
public function index()
{
$tasks = DB::table('tasks')->get();
return view('tasks', ['tasks' => $tasks]);
}
}
Thank you for any answers and if you need more information, please say so.
Given that you are using default Laravel installation, the current directory of controllers does not exist.
Try changing
<?php
namespace App\Http\Controllers\Controller;
to
<?php
namespace App\Http\Controllers;
in your TasksController.php file
Your namespace (in controller file) is App\Http\Controllers\Controller and should be App\Http\Controllers.

UnexpectedValueException in Route.php line 639: Invalid route action: [App\Http\Controllers\PortfolioController]

Why am I getting this error. I created a PortfolioController. Then I made a route using this
Route::get('portfolio','PortfolioController');
So in my controller page I made this.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PortfolioController extends Controller
{
//This only gets exectued when we request /portfolio/Paintings using GET
public function getPaintings()
{
return 'This RESTful controller is working!';
}
}
I get this error when typing in localhost/portfolio/paintings
From the look of your code, it looks like you're trying to setup an implicit controller route. You're close, but your route definition is a little off. You need to use controller instead of get:
Route::controller('portfolio','PortfolioController');
https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0
The following features are deprecated in 5.2 and will be removed in the 5.3 release in June 2016:
Implicit controller routes using Route::controller have been deprecated. Please use explicit route registration in your routes file. This will likely be extracted into a package.
You must declare each endpoint now.
try this
Route::get('portfolio','PortfolioController#getPaintings')
I got a similar error when there was a mistake in he file of web.php.
A correct route would like this Route::get('portfolio','YourController#yourMethod');
Use this code in routes:
Route::resource('portfolio','YourController#yourMethod');
you need to explain your function on Route.
example:
Route::methods('your-uri','YourController#YourFunction');
so you should do this:
Route::get('portfolio','PortfolioController#getPaintings');
Hope it helps
You have to consume a function of the controller instead of using the whole controller class for one request. so laravel doesn't know which of your function to use.
Try using PortfolioController#index. or Route::resource('yourroute','PortfolioController');
Try this: Route::resource('/portfolio','PortfolioController');
Hope this will work

How can I correctly setup models in Laravel 5 and fix my error?

I am currently learning Laravel 5. I have connected my database. Setup routes, created a controller, created a view and attempted a model, which is where I need help.
I used php artisan to create my model, which is in the /app directory.
When I try to visit /myer on the browser. I am getting the following error:
FatalErrorException in MyersController.php line 20:
Class 'App\Http\Controllers\Myer' not found
I have put the edited files on http://www.filedropper.com/help
I have no idea where I have gone wrong, I have messed around using "use" and ultimately all I get is that the Class can't be found. This is beginning to destroy my soul. If someone can help me, I would be forever grateful!!
Files
From MyersController.php
public function index()
{
$myers = Myer::all();
return view('myers.index')->with('myers'.$myers);
}
From routes.php
Route::get('/myer/', 'MyersController#index');
Route::resource('myer','MyersController');
From Myer.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Myer extends Model
{
//
}
From index.blade.php
<h2>Myers</h2>
<ul>
#foreach ($myers as $list)
<li>{{{ $list->name }}}</li>
#endforeach
</ul>
As you can see in the error, it tries to find the model in the same namespace as your controller: FatalErrorException in MyersController.php line 20: Class 'App\Http\Controllers\Myer' not found. In the Model, you can see it's in namespace App.
So either put
use App\Myer;
in the top of your controller under the namespace, or reference the full path where you need it:
public function index()
{
$myers = App\Myer::all();
return view('myers.index')->with('myers'.$myers);
}
But if you will use it more often in this controller, then it's more efficient to put it in the use.
P.S. Please don't let it destroy your soul.

Laravel url routes

I have encountered a problem with my routes in Laravel.
Im fairly new to laravel and coding in general, but i had no problems with my routes when working on Mint.
Now i switched to win8 and i can't seem to acces localhost/about.
I get this error:
Class App\Http\Controllers\PagesController does not exist
But my routes.php look like this:
Route::get('about', 'PagesController#about');
Under http>Controllers i have created PagesController.php
yet i get the error that PagesController does not exist.
Can someone please help me, feel like i've tried 100 options, from previous threads.
I have rewrite enabled, i've modified httpd.conf and my .htaccess
Here is my controller,
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controllers;
use Illuminate\Http\Request;
class PageController extends Controller {
public function about() {
$first = "Nichlas";
return view ('pages.about', compact('first'));
}
}

Categories