NotFoundHttpException in laravel 4.2 given when model update - laravel-4

i am receving this error in laravel 4.2.*
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
when i am updating a record.
// Routing
Route::get('projects/edit/{slug}', array('as' => 'projects.edit', 'uses' => 'ProjectsController#edit'));
Route::put('projects/update?{slug}', array('as' => 'projects.update', 'uses' => 'ProjectsController#update'));
// Controller
public function update($slug){
$pr = $this->project->whereSlug($slug)->first();
$this->project->fill(Input::all());
$this->project->save();
}
// Form
{{ Form::model($project, ['method' => 'PATCH', 'route' => ['projects.update', project->slug ],'files' => true]) }}
{{ Form::close() }}
// URL
pms2.dev/projects/update?slug
hope someone know, why i am facing this.

try to replace your routing as follow
Route::patch('projects/update', array('as' => 'projects.update', 'uses' => 'ProjectsController#update'));

Since your form's method is set to PATCH then your route should also be defined with the same verb.
Route::patch('projects/update?{slug}', array('as' => 'projects.update', 'uses' => 'ProjectsController#update'));
http://laravel.com/api/4.2/Illuminate/Routing/Router.html#method_patch
However i think POST is the more appropriate method here.

Related

LARAVEL: POST and GET routes with same name scrambling link_to_route

I got these routes:
Route::get('prefix/list/{page?}/{size?}', ['as' => 'prefix.list', 'uses' => 'MyController#getList']);
Route::post('prefix/list', ['as' => 'prefix.list', 'uses' => 'MyController#postList']);
When I call link_to_route() like so:
{{ link_to_route('prefix.list', $page, ['page' => $page, 'size' => $size]) }}
It creates this link:
http://my.site/prefix/list?page=5&size=12
But when I remove the post route, it renders correctly this:
http://my.site/prefix/list/5/12
I don't want to change the name of the routes because my system depends on them being the same. How can I solve this?
You could try just changing the order of the routes in your routes file, so that the get one comes last and overrides the post for the purposes of link_to_route().

How get laravel route alias?

I have next code
Route::group(['as' => 'admin.search.'], function () {
Route::get('admin/query', ['uses' => 'Admin\AdminSearchController#query', 'as' => 'query']);
Route::get('admin/search', ['uses' => 'Admin\AdminSearchController#index', 'as' => 'index');
Route::post('admin/search', ['uses' =>'Admin\AdminSearchController#search', 'as' => 'full');
});
And i check route in layout
#if (!Route::is('admin.search.index') || !Route::is('admin.search.full'))
#include('partials.forms.global_search')
#endif
But is not work. How i can know route which now i am ?
You could use this function, it returns you route name in your case it will be admin.search.query etc...
Route::getCurrentRoute()->getName()
And check it's !Route::is('admin.search.full') doesn't make sense because it's a post route handler.
In your case code will be
#if (Route::getCurrentRoute()->getName() === 'admin.search.search')
#include('partials.forms.global_search')
#endif

DaveJamesMiller Breadcrumbs Error - Laravel

I am currently trying to set up breadcrumbs for my Laravel 5 application. Unfortunately, I am currently being presented with this error when I access localhost:8888/auth/login:
ErrorException in
/Users/ben/Sites/laravel/vendor/davejamesmiller/laravel-breadcrumbs/src/CurrentRoute.php
line 29
The current route (GET /auth/login) is not named - please check
routes.php for an "as" parameter
Routes.php:
Route::get('auth/login', 'Auth\AuthController#getLogin',
['as' => 'login', 'uses' => 'Auth/AuthController#getLogin']);
The error is shown with or without the ['as' => 'login', 'uses' => 'Auth/AuthController#getLogin'] addition.
Breadcrumbs.php
Breadcrumbs::register('login', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Login', route('login'));
});
Thank you for your help.
I resolved this issue by changing the route to the following:
Route::get('auth/login',
['as' => 'login', 'uses' => 'Auth/AuthController#getLogin']);
You can only declare which controller method you're using once.

Getting NotFoundHttpException for my edit route

This is my route
Route::get(
'account-executive/{$id}/edit',
array(
'as' => 'vendor-edit',
'uses' => 'AdminController#updateVendor'
)
);
This is my method
public function updateVendor($id)
{
$vendor = Vendor::findOrFail($id);
return View::make('admin.edit-account-executive');
}
I keep getting NotFoundHttpException. Any ideas as to why?
Your route definition isn't correct.
Route::get('account-executive/{$id}/edit', array('as' => 'vendor-edit','uses' => 'AdminController#updateVendor'));
You don't need a $ sign in definition of route parameter. So you should just write account-executive/{id}/edit.
Try it.

Laravel Routes Artisan

When I run artisan routes in laravel 4
auth/login/{v1}/{v2}/{v3}/{v4}/{v5}
Is this normal or is there something wrong. My routes work just wondering if there might be a bug or something. Below are my routes for auth. I'm using restful routes for auth.
Route::controller('auth','AuthController');
Route::get('AuthController/login', array('as' => 'login', 'uses' => 'AuthController#login'));
Route::get('auth/logout', array('as' => 'logout', 'uses' => 'auth#logout'));
Route::post('auth/login', array('uses' => 'auth#login'));
This is expected. When you register controllers with Route::controller() the controller inspector adds the URI wildcards. Consider the following example:
Route::controller('user', 'UserController');
You might then have a method like this on your UserController:
public function getProfile($username)
{
$user = User::where('username', $username)->first();
return View::make('profile')->with('user', $user);
}
You could then hit that method by going to localhost/yourapp/user/profile/jason
In a nut shell it allows you to pass extra parameters to a method. To me this is a very old school way of doing it, as it looks nicer like localhost/yourapp/user/jason/profile and in this case you'd need to use a route to map to the controller method.
I suggest you 2 improvements:
1 - keep a standard with URIs
You don't need Route::controller in this case. In order to mantain all routes with the same structure I would do:
Route::group( array('prefix'=>'auth,function(){ //make all auth routes starting by auth
Route::get('getLogin', array('as' => 'getLogin', 'uses' => 'AuthController#getLogin'));
Route::get('getLogin', array('as' => 'logout', 'uses' => 'AuthController#logout'));
Route::post('postLogin', array('as' => 'postLogin', 'uses' => 'AuthController#postLogin'));
});
It is not necessary to use group but if you app grows could be better. Without group code will be:
Route::get('auth/getLogin', array('as' => 'getLogin', 'uses' => 'AuthController#getLogin'));
Route::get('auth/getLogin', array('as' => 'logout', 'uses' => 'AuthController#logout'));
Route::post('auth/postLogin', array('as' => 'postLogin', 'uses' => 'AuthController#postLogin'));
2 - Protect your post routes
For every post and put request we've to prevent CSRF attacks like this:
Route::post('postLogin',array('before' => 'csrf','uses'=>AuthController#postLogin) );

Resources