route laravel not defined - laravel

i have this route:
Route::get('blog/search', 'web\BlogController#localSearch')->name($this->prefix.'blogSingle.localSearch');
this route it´s inside group:
Route::group(['prefix' => $locale, 'where' => ['locale' => '[a-zA-Z]{2}']], function(){
//Route::get('/', 'Web\HomeController#index')->name($this->prefix.'home.index');
Route::get('/', 'Web\ManagerController#index')->name($this->prefix.'home.index');
Route::get('about', 'Web\AboutController#index')->name($this->prefix.'about.index');
Route::get('contact', 'Web\ContactController#index')->name($this->prefix.'contact.index');
Route::get('help', 'Web\HelpController#index')->name($this->prefix.'help.index');
Route::get('local/{url}', 'Web\LocalController#index')->name($this->prefix.'local.index');
Route::get('privacy-policy', 'Web\PrivacyController#index')->name($this->prefix.'privacy.index');
Route::get('managers', 'Web\ManagerController#index')->name($this->prefix.'manager.index');
Route::get('blog', 'Web\BlogController#index')->name($this->prefix.'blog.index');
Route::get('search', 'Web\SearchController#index')->name($this->prefix.'search.index');
Route::get('suggest-local', 'Web\SuggestController#index')->name($this->prefix.'suggest.index');
Route::get('terms-conditions', 'Web\TermController#index')->name($this->prefix.'term.index');
Route::get('blog/{url}', 'web\BlogController#show')->name($this->prefix.'blogSingle.show');
Route::get('blog/likeit/{id}', 'web\BlogController#likeit')->name($this->prefix.'blogSingle.likeit');
Route::get('blog/search', 'web\BlogController#localSearch')->name($this->prefix.'blogSingle.localSearch');
Route::get('password/reset/{token}', 'Auth\ResetPasswordController#showResetForm')->name($this->prefix.'password.reset');
Route::get('email/verify/{id}', 'Auth\VerificationController#verify')->name($this->prefix.'verification.verify');
});
}
but i need call to action form:
<form action="{{ route('blog/search') }}" method="get" class="fl-wrap" id="searchRestaurant">
and when send my form, returned this:
Route [blog/search] not defined. (View: C:\wamp64\www\guiaPaladar\resources\views\layouts\right_sidebar_blog.blade.php)
this error appear when blade load, so i can´t do anything
i don´t show my wrong, others routes i can use in other form, for example blog/likeit/{id} i used in href to add like in post blog...
i hope that anybody can help me, please. Sorry for my english
Thanks

If you are sure that the route blog/search is registered after using php artisan route:list to check. However, your change is not reflected; You may have to clear cache. Please use the following command:
php artisan route:clear

Related

GET (405) method not allowed [duplicate]

Im trying to do a POST request with jQuery but im getting a error 405 (Method Not Allowed), Im working with Laravel 5
THis is my code:
jQuery
<script type="text/javascript">
$(document).ready(function () {
$('.delete').click(function (e){
e.preventDefault();
var row = $(this).parents('tr');
var id = row.data('id');
var form = $('#formDelete');
var url = form.attr('action').replace(':USER_ID', id);
var data = form.serialize();
$.post(url, data, function (result){
alert(result);
});
});
});
</script>
HTML
{!! Form::open(['route' => ['companiesDelete', ':USER_ID'], 'method' =>'DELETE', 'id' => 'formDelete']) !!}
{!!Form::close() !!}
Controller
public function delete($id, \Request $request){
return $id;
}
The Jquery error is http://localhost/laravel5.1/public/empresas/eliminar/5 405 (Method Not Allowed).
The url value is
http://localhost/laravel5.1/public/empresas/eliminar/5
and the data value is
_method=DELETE&_token=pCETpf1jDT1rY615o62W0UK7hs3UnTNm1t0vmIRZ.
If i change to $.get request it works fine, but i want to do a post request.
Anyone could help me?
Thanks.
EDIT!!
Route
Route::post('empresas/eliminar/{id}', ['as' => 'companiesDelete', 'uses' => 'CompaniesController#delete']);
The methodNotAllowed exception indicates that a route doesn't exist for the HTTP method you are requesting.
Your form is set up to make a DELETE request, so your route needs to use Route::delete() to receive this.
Route::delete('empresas/eliminar/{id}', [
'as' => 'companiesDelete',
'uses' => 'CompaniesController#delete'
]);
Your routes.php file needs to be setup correctly.
What I am assuming your current setup is like:
Route::post('/empresas/eliminar/{id}','CompanyController#companiesDelete');
or something. Define a route for the delete method instead.
Route::delete('/empresas/eliminar/{id}','CompanyController#companiesDelete');
Now if you are using a Route resource, the default route name to be used for the 'DELETE' method is .destroy. Define your delete logic in that function instead.
In my case the route in my router was:
Route::post('/new-order', 'Api\OrderController#initiateOrder')->name('newOrder');
and from the client app I was posting the request to:
https://my-domain/api/new-order/
So, because of the trailing slash I got a 405. Hope it helps someone
If you didn't have such an error during development and it props up only in production try
php artisan route:list to see if the route exists.
If it doesn't try
php artisan route:clear to clear your cache.
That worked for me.
This might help someone so I'll put my inputs here as well.
I've encountered the same (or similar) problem. Apparently, the problem was the POST request was blocked by Modsec by the following rules: 350147, 340147, 340148, 350148
After blocking the request, I was redirected to the same endpoint but as a GET request of course and thus the 405.
I whitelisted those rules and voila, the 405 error was gone.
Hope this helps someone.
If you're using the resource routes, then in the HTML body of the form, you can use method_field helper like this:
<form>
{{ csrf_field() }}
{{ method_field('PUT') }}
<!-- ... -->
</form>
It will create hidden form input with method type, that is correctly interpereted by Laravel 5.5+.
Since Laravel 5.6 you can use following Blade directives in the templates:
<form>
#method('put')
#csrf
<!-- ... -->
</form>
Hope this might help someone in the future.
When use method delete in form then must have to set route delete
Route::delete("empresas/eliminar/{id}", "CompaniesController#delete");
I solved that issue by running php artisan route:cache which cleared the cache and it's start working.
For Laravel 7 +, just in case you run into this, you should check if the route exists using
php artisan route:list
if it exists then you need to cache your routes
php artisan route:cache

Route keep asking for parameter even if not set to receive any

I'm new to laravel and I'm having trouble with one of my web routes...
I grouped some routes with the auth middleware
Route::middleware(['auth:web'])->group(function ($router) {
Route::get('/news', [NewsController::class, 'news'])->name('news');
Route::get('/profile/{user_id}', [ProfileController::class, 'profile'])->name('profile');
Route::get('/marketplace', [MarketplaceController::class, 'marketplace'])->name('marketplace');
});
Before this issue, I have set a user_id parameter for the news route and then removed it the next day, now the news route keeps returning error saying it needs user_id.
here's my controller:
<?php
namespace App\Http\Controllers;
class NewsController extends Controller
{
public function news() {
return view('modules.news.news');
}
}
and since im using laravel-vue mix, my modules.news.news view looks like this:
#section('content')
<newsfeed inline-template>
<div>
...
...
</div>
</newsfeed>
#endsection
I've checked the web route, the controller, the blade, and I really can't see anything that requiring the news route to receive a parameter.
can someone point out where I went wrong?
Your route file might be cached, try running php artisan route:clear and see if this fixes the issue.

Routing error in Laravel 5.3

I may be being thick but I am continually getting a page notfoundexception .
In a view I have the following:
<a href="{{ route('/galleryimages/{id}') }}"
This part is OK. In web.php I have:
Route::get('/galleryimages/{{id}}', function($id){
return view('gallery_pictures.pictures',['id'=>$id]);
});
The page pictures definitely exists in the subdirectory gallery_pictures.
Your route is incorrect, Laravel route parameters use one curly braces, like so: {id}. Rather than {{id}}
The helper function you are using accepts route names not route URL's, to link routes you should use the url() function
https://laravel.com/docs/5.3/helpers
https://laravel.com/docs/5.3/routing
I've provided you some for reference links if you haven't already checked them out.
HTML Fix:
My Link
Route Fix:
Route::get('/galleryimages/{id}', function($id) {
return view('gallery_pictures.pictures', ['id'=> $id]);
});
A little extra
If you want to use the route function you must set a name for your route, you can do it as so:
Route::get('/galleryimages/{id}', function($id) {
return view('gallery_pictures.pictures', ['id'=> $id]);
})->name('gallery_images');
Then you may access the route by doing something like so
My Link

Laravel routing resource error

i'm using laravel 5.0
I have 2 routing :
Route::get('admin', 'AdminController#index');
Route::resource('admin/user','UserController');
If I browse to http://localhost:8000/admin/user
It works fine
but if I using this :
Route::resource('admin', 'AdminController');
Route::resource('admin/user','UserController');
The page at http://localhost:8000/admin/user will be blank!
Why? and how to fix it ?
Thank you
Follow this order:
Route::get('admin', 'AdminController#index');
Route::resource('admin/user','UserController');
Route::resource('admin', 'AdminController');
It's just the problem with the priority of the routes.
The route, Route::get('admin/{id}', 'AdminController#show') will take precedence over the Route::get('admin/user', 'UsersController#show');

Laravel 4: Unable to generate a URL for the named route "login" as such route does not exist

I'm creating an authorization system in my Laravel 4 project. I am trying to use the auth "before" filter.
In my routes.php file, I have:
Route::get('viewer', array('before' => 'auth', function() {
return View::make('lead_viewer');
}));
Route::get('login', 'LoginController');
The before filter calls this line in the filters.php file:
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::route('login');
});
I can manually navigate to my login route. But the auth system isn't letting this happen. I've run composer dump-autoload a couple of times, so that isn't the problem. What am I doing, since I can actually load the login page if I do it manually?
I figure it out. Laravel is looking for a named route: I had to do this:
Route::get('login', array('as' => 'login', function() {
return View::make('login');
}));
An interesting, not very intuitive approach in Laravel. But there must be a reason Taylor did this that I'm not seeing.
To do what you were trying to do in your initial approach you could have just done:
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::to('/login');
});
and it would have worked just fine.
If you want to use named routes then you do what you posted in your answer to your own question. Essentially...more than one way to skin a cat.
Hope that helps
I know you've probably solved this by now but after stumbling across your post while trying to solve a similar problem, I wanted to share my thoughts...
Laravel is NOT looking for a named route for the guest method, it is expecting a path.
Your example works because because the named route and the path are the same i.e. "login". Try changing your URL to something other than 'login' and watch it fail.
If you want to use a named route you should use the route helper method as so...
if (Auth::guest()) return Redirect::guest( route('login') )
Hope that helps someone.

Resources