PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 25, 2022

[FIXED] Laravel:Method ...Controller::show does not exist

 January 25, 2022     laravel, laravel-5.6     No comments   

Issue

I'm trying to validate post request. I think when the validation fails, it gives me this error message.

app/Http/Controllers/InternationalShippingController.php

public function store(Request $request){
    //echo '<pre>';
    $post = $request->post();
    $order_ids = session('international_order_ids');
    //var_dump($order_ids);
    //var_dump($post);

    $validator = Validator::make(
      $post,[
          'documents.*' => 'mimes:jpg,jpeg,png,pdf|max:5000|nullable',
          'company_name' => 'nullable',
          'shipping_address1' => 'nullable',
          'message' => 'size:1000',
        ],[
            'image_file.*.mimes' => __('Only jpeg,png and pdf files are allowed'),
            'image_file.*.max' => __('Sorry! Maximum allowed size for an document is 5MB'),
        ]
    );

    if($validator->fails()){
        return redirect('internationalshippings/create2')
            ->withErrors($validator)
            ->withInput();
    }
}

web.php

Route::post('internationalshippings/create2','InternationalShippingController@create2');
Route::resource('internationalshippings','InternationalShippingController');

I haven't made show() method in the controller. Does this error mean when the validation fails, it tries to redirect to internationalshippings/show method? When the validation fails,I'd like this to redirect back to internationalshippings/create2. How can I achieve this?

Thank you


Solution

you are using the resource controller, in resources this url internationalshippings/SomeThing means the show method i mean this url calls the show method in resource

First way
so you can use this in your fail return:
return redirect()->route('your_route_name') OR return back()

Second way
and the second way is in your web.php, when you are defining the resource route, type in this way:
Route::resource('internationalshippings','InternationalShippingController',['except'=>['show']]);


EDIT:
in your code situation the best way is change Return, because the url that you want to redirect to it, is POST



Answered By - Reza sh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing