I'm facing a problem in Laravel. It seems that sometimes the Laravel framework loads an old version of a controller.
I created a new function and sometimes Laravel found it and sometimes it returns that the method does not exist.
What could be the problem in this case?
This is my function:
public function test(){
echo 'Here'; exit();
return view('welcome');
}
The Page sometimes show only Here (which is correct) and sometimes it redirects me to the welcome blade without showing the Here message.
Please make sure you are define the url in web.php within route folder
or use this command
php artisan cache:clear
php artisan config:cache
Related
I'm trying to develope a program with Laravel, I have a problem with a Route, it shows me that is not define but it's already defined, also, I'm using Ajax.
This is the Error
This is my Ajax with URL and Route
And I tried to put the Route in that part of the code, but when I put there I get other problem.
I have tried this
Thank so much for your help.
After adding new route you need to clear cache. So run this commands:
php artisan cache:clear
php artisan route:cache
And check again
You have same controller method two time define and you did changed only route name? so it can return error. remove first route then it will work fine.
Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('client.schedules.destory');
Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('orders.schedules.store');
please remove Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('client.schedules.destory'); route.
I have some issues with Laravel. I called php artisan route:cache and then the issues began. For example, the Auth routes (login etc.) can be called even if the User is logged in. Then the caching command seems to not clearing the routes. I noticed it because I put my Auth routes in the middleware guests because of the rendering of the Auth routes. After I ran route: clear it worked.
Also, the 404 routing doesn't work since that, because if I call a route that doesn't exist, then the Symfony Framework throws an error:
Symfony\Component\Routing\Exception\ResourceNotFoundException
That's my web.php:
Route::get("/installer","install\InstallController#index");
Route::group(["middleware"=>"guest"],function(){
Auth::routes();
Route::post("login","Auth\Logincontroller#authenticate");
});
Route::group(["middleware" => "auth"], function () {
Route::get("/logout","Auth\LoginController#logOut");
Route::get('/', "dashboard\DashboardController#index");
});
Also, the installer route doesn't work. I will always get redirected to localhost/dashboard (even if I change the route name). My domain for the Laravel is called raptor.debug, so I don't know why it's redirecting to localhost.
Can someone point out what I did wrong or is this a bug?
As Anas Bakro pointed out, the command php artisan route:cache will brick the app, when the folder of the controllers are lowercased.
I Blog in Laravel v5.6
when translate new route it doesn't work for me
but old route like login and register and landing pages it working as well when i going in new route it's not
Switch Lang page
Route::get('locale/{locale}', function ($locale) {
Session::put('locale', $locale);
return redirect()->back();
// this link will add session of language when they click to change langauge
})->name('locale');
Route::get('/{username}', 'ProfileAccountController#index')->name('profile')->middleware('admin.user');
when i going to this route it's not working and navbar and footer it's back to key, remove all code in this page and test the lang it's not work too.
I use all of this command and nothing
php artisan config:cache
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
Thank you.
My suggestions:
Use middle-wear for changing languages and use https://github.com/spatie/laravel-translatable like this for more comfortable usage.
Also check this Change language in Laravel 5 might help you.
Had similar issues with Route closures. Try moving you're session setters/getters to a Controller and not within a Route closure.
https://laravel.com/docs/5.7/session#using-the-session
This will probably solve your issues.
I'm a beginner using this laravel framework. Currently i'm trying to understand the routing and controller of this framework.
I created a controller file using this command:
php artisan make:controller Admin/PostController
Of course the output of this is to create a controller file inside Admin folder. Inside of the PostController.php i wrote a code like this:
public function create()
{
return view('admin.post.post');
}
Also, in my web.php i have this code.
Route::get('/', function () {
return view('user.blog');
});
Route::get('posts',function(){
return view('user.posts');
})->name('posts');
Route::resource('admin/post','Admin\PostController');
The "admin" is a folder and the "post" is a folder too inside the "admin" and when you open the "post" folder you'll see the "post.blade.php" file. The other two route::get in my web.php are working fine. But the route:resource is not working.
When i tried to run this in my browser using this link:
localhost:8000/admin/post/create
The browser says: Sorry, the page you are looking for could not be found
Is there any problem with syntax or path structures?
Here's my post.blade.php
#extends('admin.layouts.app')
#section('main-content')
this is just html codes..
#endsection
Here's my php artisan route:list
this because some time composer stuck, for that times you should stop serve and re generate autoload
1.stop your php artisan serve
2.enter this command
composer dumpautoload
3.run your php artisan serve
I have been encountering a weird problem with Laravel over the last week.
Basically, lets say for example that I am editing a view, "view.blade.php", and the controller, "ViewController.php", and I am constantly refreshing the browser page to see my changes.
My view is loaded by the index() function of my ViewController like so:
public function index()
{
return view('view');
}
Everything is working and I am seeing my changes reflected in the browser. However, all of a sudden for some reason, the page goes white and my view stops loading. No error in Laravel.log or console, nothing. It just shows a white page.
The thing is, if I change the name of my view file to "view2.blade.php" and change my index function to return 'view2' instead, the page loads as normal and works perfectly. It seems that the file name is the only thing keeping the page from loading.
I have tried clearing all the caches with the following artisan commands:
php artisan route:cache
php artisan cache:clear
php artisan view:clear
php artisan config:cache
and executing php artisan optimize
However, the problem still persists. I have not modified or added any vendor files.
This doesn't happen too often but it is annoying and it normally "magically" solves itself when I leave it alone for a while to work on another view/controller. However, I just want to know if anyone else has this problem and if there is a solution anywhere.
I defined my route like so:
Route::resource('view', 'ViewController');
Using Laravel 5.4
try to clear browser cash ctrl + F5
Hey try this url http://yoursite.dev/view/, do note you need to replace the yoursite.dev with your local domain.
By including the 'view' string in the resource function you are making a restful resource relative to the /view base domain.
Here is a link to the docs https://laravel.com/docs/5.4/controllers#resource-controllers
reference the table Actions Handled By Resource Controller for a thorough explanation.