Laravel 5 form submit creates an error MethodNotAllowedHttpException - php

I'm using Laravel 5. When editing a form a get this error
MethodNotAllowedHttpException
There are a few posts but I think it may be code specific. I'd rather not use the resource route methods if possible. Route:
Route::get('profile/edit', array('as' => 'admin.profile.edit', 'uses' => 'ProfileController#edit'));
Route::post('profile/edit', array('as' => 'admin.profile.update', 'uses' => 'ProfileController#update'));
The form is :
{!!Form::model($profile,array('method'=>'Patch','route' =>array('admin.profile.update'))) !!}
Controller:
public function update()
{
$user_id=$this->user->id;
$input=array_except(Input::all(),'_method');
Profile::where('user_id','=',$user_id)->update($input);
return Redirect::route('admin.profile.index');
}
Here is the error info:
n RouteCollection.php line 207
at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 194
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD', 'POST')) in RouteCollection.php line 142
at RouteCollection->match(object(Request)) in Router.php line 729
at Router->findRoute(object(Request)) in Router.php line 652
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
Thanks any help appreciated

Can you change this:
Route::post('profile/edit', array(
'as' => 'admin.profile.update',
'uses' => 'ProfileController#update'
));
To this:
Route::patch('profile/edit', array(
'as' => 'admin.profile.update',
'uses' => 'ProfileController#update'
));
I think your form action may need a matching route verb
http://laravel.com/docs/5.1/routing#basic-routing
For the second issue:
Column not found: 1054 Unknown column '_method' in 'field list' (SQL: update user_profile` set _method = PATCH, _token =
Add this to the top of your controller
use Illuminate\Http\Request;
Then update your method as so:
public function update(Request $request)
{
$user_id = $this->user->id;
$input = $request->except('_method', '_token');
Profile::where('user_id','=', $user_id)->update($input);
return Redirect::route('admin.profile.index');
}

In my case works adding protected $guarded = ['_token']; in Model file.

Related

ErrorException in HasAttributes.php / Illegal offset type

i have problem in storing data of users ,when user sign up i store half of info in table user and other half in another table ,when hit register butttom i get that error i found that in table user info is stored correctley but in other table nothing is saved.
error
in HasAttributes.php line 818
at HandleExceptions->handleError(2, 'Illegal offset type', 'C:\\wamp\\www\\Menoon1\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php', 818, array()) in HasAttributes.php line 818
at Model->getCasts() in HasAttributes.php line 803
at Model->hasCast('email', array('date', 'datetime')) in HasAttributes.php line 832
at Model->isDateCastable('email') in HasAttributes.php line 565
at Model->isDateAttribute('email') in HasAttributes.php line 525
at Model->setAttribute('email', 'dde#hg.com') in Model.php line 223
at Model->fill(array('email' => 'dde#hg.com')) in Model.php line 145
at Model->__construct(array('email' => 'dde#hg.com')) in Model.php line 268
at Model->newInstance(array('email' => 'dde#hg.com')) in Builder.php line 1030
at Builder->newModelInstance(array('email' => 'dde#hg.com')) in Builder.php line 723
at Builder->create(array('email' => 'dde#hg.com')) in Model.php line 1332
at Model->__call('create', array(array('email' => 'dde#hg.com'))) in Model.php line 1344
at user_emails->create(array('email' => 'dde#hg.com')) in Model.php line 1344
at Model::__callStatic('create', array(array('email' => 'dde#hg.com'))) in RegisterController.php line 94
at user_emails::create(array('email' => 'dde#hg.com')) in RegisterController.php line 94
at RegisterController->create(array('_token' => 'FZqd7Sc3fQRzmaQ0ImXYebzltzkygJsbKpNcZhv4', 'username' => 'vbnm v bnmm', 'email' => 'dde#hg.com', 'password' => '1111111', 'password_confirmation' => '1111111', 'fname' => 'vbn', 'lname' => 'bnm', 'address' => 'bnm', 'membership' => 'Normal', 'pic' => object(UploadedFile))) in RegistersUsers.php line 33
at RegisterController->register(object(Request))
at call_user_func_array(array(object(RegisterController), 'register'), array(object(Request))) in Controller.php line 55
at Controller->callAction('register', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(RegisterController), 'register') in Route.php line 204
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in RedirectIfAuthenticated.php line 24
at RedirectIfAuthenticated->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\\wamp\\www\\Menoon1\\public\\index.php') in server.php line 21
user mode
public function useremail()
{
return $this->hasOne('App\user_emails');
}
other table code
public function user()
{
return $this->belongsTo('App\User');
}
code in registercontroller
protected function create(array $data)
{
$fileName = 'null';
Input::file('pic')->store('avatars');
if (Input::file('pic')->isValid()) {
$destinationPath = public_path('uploads/files');
$extension = Input::file('pic')->getClientOriginalExtension();
$fileName = uniqid().'.'.$extension;
Input::file('pic')->move($destinationPath, $fileName);
}
$user= User::create([
'fname' => $data['fname'],
'lname' => $data['lname'],
'address' => $data['address'],
'username' => $data['username'],
'membership' => $data['membership'],
'pic'=>$fileName,
'password' => bcrypt($data['password']),
]);
$useremail=user_emails::create(['email'=>$data['email']]);
// dd($useremail);
$user->useremail()->save($useremail);
return $user;
}
I dont know your model, but if has composite keys, collection cannot get attributes
Try
$user->useremail()->save(new UserEmail(['email'=>$data['email']]));
Given that the model of the useremail is UserEmail.
And your models are mixed up: it should be for App\UserEmail:
public function user()
{
return $this->belongsTo('App\User');
}
and for App\User
public function userEmail()
{
return $this->hasOne('App\user_emails');
}
Notice the convention, for your own good. 'useremail' becomes userEmail'. The model files become User.php and UserEmail.php. Your tables 'users' and 'user_emails' respectively. As thus, the relationship in 'user_emails' should be 'user_id'. And done.
I faced the same issue, it happened because in the Model I defined also a primary key, but it was already set in the database with a clause when the table was created.

Lumen: $user is null inside Policy

I am trying to validate if a user exists inside a Policy in Lumen.
This is my Controller function:
public function create(Request $request)
{
$rules = array(
'content' => 'required|string',
);
$user = $request->user();
$this->validate($request, $rules);
$this->authorize('create', Card::class);
This is the Policy:
public function create(User $user)
{
// As long as the user is real, allowed
return $user->id != null;
}
The $user inside the create Policy seems to be null. This is the error:
HttpException in Handler.php line 90:
This action is unauthorized.
in Handler.php line 90
at Handler->render(object(Request), object(AuthorizationException)) in Handler.php line 48
at Handler->render(object(Request), object(AuthorizationException)) in Pipeline.php line 78
at Pipeline->handleException(object(Request), object(AuthorizationException)) in Pipeline.php line 54
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in Authenticate.php line 42
at Authenticate->handle(object(Request), object(Closure), 'api') in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in RoutesRequests.php line 780
at Application->sendThroughPipeline(array('App\\Http\\Middleware\\Authenticate:api'), object(Closure)) in RoutesRequests.php line 626
at Application->handleFoundRoute(array(true, array('uses' => 'App\\Http\\Controllers\\CardController#create', 'middleware' => array('auth:api')), array())) in RoutesRequests.php line 528
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in ExampleMiddleware.php line 18
at ExampleMiddleware->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in RoutesRequests.php line 780
at Application->sendThroughPipeline(array('App\\Http\\Middleware\\ExampleMiddleware'), object(Closure)) in RoutesRequests.php line 534
at Application->dispatch(object(Request)) in RoutesRequests.php line 475
at Application->run(object(Request)) in index.php line 29
I meet the same problem.
But the issue is nothing about the policy class.
This is resolved by using fully qualified class name in AuthServiceProvider file,
change:
Gate::policy(Post::class, PostPolicy::class);
to:
Gate::policy(\App\Post::class, \App\Policies\PostPolicy::class);
hope this help.

Redirect with parameters laravel 5.3 | InvalidArgumentException in Response.php line 462

Hi I'm new to laravel and got stuck.
in my app there are three types of users. their login data is kept in a single table(users table generated with auth), with a char to define the user type. What I want to do is when they log in, redirect them to relevant page with their user_id (obtained from the users table) on the url.
bottomline is I want to get the url as
localhost:8000/ESProfile/15
where value 15 is the user_id of the table.
What I've done so far is below.
In AuthenticatesUsers.php (auto generated from artisan auth)
protected function authenticated(Request $request, $user)
{
$userId = $user->id;
if($user->type === 's') {
return redirect('ESProfile', $userId);
}
else if($user->type === 'p') {
return redirect('/ePProfile');
}
else if($user->type === 'i') {
return redirect('/ePDashboard');
}
}
In web.php
Route::get('ESProfile/{id}', function($id){ return view('ESeeker.details')->with('$id'); });
when I try to login, it gives
InvalidArgumentException in UrlGenerator.php line 314: Route [ESProfile] not defined. error.
along with
in UrlGenerator.php line 314
at UrlGenerator->route('ESProfile', array('15'), true) in helpers.php line 692
at route('ESProfile', array('15')) in AuthenticatesUsers.php line 123
at LoginController->authenticated(object(Request), object(User)) in AuthenticatesUsers.php line 107
at LoginController->sendLoginResponse(object(Request)) in AuthenticatesUsers.php line 46
at LoginController->login(object(Request))
at call_user_func_array(array(object(LoginController), 'login'), array(object(Request))) in Controller.php line 55
at Controller->callAction('login', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(LoginController), 'login') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in RedirectIfAuthenticated.php line 24
at RedirectIfAuthenticated->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\Project\public\index.php') in server.php line 21
Thanks in advance.
In your view, you must be using following code
route('ESProfile', ['id' => $id])
which will obviously fail because you have not defined ESProfile anywhere.
Change your route to following to wrok:
Route::get('ESProfile/{id}', function($id) {
return view('ESeeker.details')->with('$id');
})->name('ESProfile');
Check docs for named routes.
After many trials found my answer.
In RegistersUsers.php (auto generated file from php artisan make:auth)
public function register(Request $request){
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
$user = $request -> user();
if(($user->type) == 's'){
return $this->registered($request, $user)?: redirect()-> intended('/addPreferences/ESId='.$user->id);
}
if(($user->type) == 'p'){
return $this->registered($request, $user)?: redirect()-> intended('/ePProfile/epID='.$user->id);
}
}
appending desired path with intended method did the trick. Thanks.
(special thanks goes to iCode)

How do I solve this "NotFoundHttpException" error in Laravel 5.1

I'm getting this error, while trying to access a page that I've added in my routes..
ex. laravel.com/about-us
here's a sample of my routes code.
I was asked to do the routes in config.php
'about-us' => [
'controller' => 'page',
'method' => 'about',
'enable' => true
],
and a method like this.
public function about() {
return view($this->getViewPrefix() . '::page.about');
}
The ful error:
NotFoundHttpException in Application.php line 879:
in Application.php line 879
at Application->abort('404', '', array()) in helpers.php line 21
at abort('404') in helpers.php line 45
at cd_abort('404') in routes.php line 93
at ServiceProvider->{closure}('about-us')
at call_user_func_array(object(Closure), array('param1' => 'about-us')) in Route.php line 155
at Route->runCallable(object(Request)) in Route.php line 130
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
I personally don't think it's how I did these things, because one of my colleagues got two of these pages to work, (they only have two) ..
does this have to do with my installation, or maybe my OS lol.?
I don't think you can write routes in config file. You have to write your routes in this file app/Http/routes.php Write these lines
Route::get('about-us', [
'as' => 'aboutUs', 'uses' => 'PagesController#about'
]);
Write your controller's name instead of PagesController. You have to make your controller inside this folder app/Http/Controllers
Laravel has the routes.php file to contain all the application related routing. This file will be autoloaded when the application runs.
Therefore, include your routing in this file for best practice.
A "get" routing will be like:
Route::get('/about-us', [ 'as' => 'about', 'uses' => 'PagesController#about']);
Similarly a 'post' routing:
Route::post('/about-us', [ 'as' => 'about', 'uses' => 'PagesController#about']);
Remember to name the controller file as "PagesController". Its the proper naming convention.
"#about" is the method in the PagesController that will handle the logic.
For better understanding: Laravel Routing
Hope this is helpful.

Laravel 5 Routing Issue - Bad Method Call Exception

I'm attempting to simply send a 'PUT' request to one of my routes (which is called as a resource in the route file), yet I recieve this traceback as the response.
Whoops, looks like something went wrong.
1/1 BadMethodCallException in Controller.php line 273: Method [show] does not exist.
in Controller.php line 273
at Controller->__call('show', array('1'))
at AccountControllerV2->show('1')
at call_user_func_array(array(object(AccountControllerV2), 'show'), array('account' => '1')) in Controller.php line 246
at Controller->callAction('show', array('account' => '1')) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(AccountControllerV2), object(Route), 'show') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(AccountControllerV2), object(Route), object(Request), 'show') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\API\V2\AccountControllerV2', 'show') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 692
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 47
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 694
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 661
at Router->dispatchToRoute(object(Request)) in Router.php line 619
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in HttpsProtocol.php line 15
at HttpsProtocol->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
I cannot for the life of me figure out why this is happening.
Here is a code snippet from the Controller itself (which extends BaseController):
/**
* Update the currently logged User in storage.
*
* #return Response 201
* #return jsonArray account
* #return string message
*/
public function update($account_id) {
$input = Input::all();
$message = 'Account Successfully Updated';
$user = Auth::User();
And here is the Route declaration:
Route::group(array('prefix' => 'api/v2', 'namespace' => 'API\V2', 'middleware' => 'auth'), function()
{
Route::resource('challenges', 'ChallengeControllerV2', ['only'=> ['index','store','update','destroy']]);
Route::resource('groups', 'GroupControllerV2');
Route::resource('account', 'AccountControllerV2');
The call is being made to the correct path. Any ideas why I'm getting what seems to be an illogical response? There is no additional middleware/filters attached to the controller than what is shown.
It turns out that in Laravel 5 if you do not specify the resources available on a Route it will assume that they are all there (unlike in Laravel 4 where it checks to see what resources are available in all controllers). So I had to change the line like so.
Route::resource('account', 'AccountControllerV2', ['only'=> ['index','update','destroy']]);

Categories