BadMethodCallException Method App\Http\Controllers\CvController::create does not exist - laravel

Having the issue when loading the cvs/create being return an error of;
My route file;
My CvController;
Application frames (1)

in your route
CvController#create
but in your CvController
public function cerate()
spellings mistake.
create != cerate

There is a spell mistake in your function
public function create() {
return view('cv.create');
}

Related

Route not defined when passing parameter to a route

I have a named route with a parameter which looks like this...
Route::get('/profile/{user_id}', [ProfileController::class, 'profile'])->name('profile');
Now in one of my controller,
I have a function that calls this route like this
public function _myFunction($some_data) {
return redirect()->route('profile', [$some_data->user_id]);
}
and in my ProfileController's profile() function, I have this.
public function profile() {
return view('modules.profile.profile');
}
I've followed the documentation and some guides I found in SO, but I got the same error,
"Route [profile] not defined."
can somebody enlighten me on where I went wrong?
Here's what my routes/web.php looks like...
Route::middleware(['auth:web'])->group(function ($router) {
Route::get('/profile/{user_id}', [ProfileController::class, 'profile'])->name('profile');
});
When calling the route, you should pass the name of the attribute along with the value (as key vaue pairs). In this case, your route is expecting user_id so your route generation should look like this:
return redirect()->route('profile', ['user_id' => $some_data->user_id]);
Read more on Generating URLs To Named Routes in Laravel.
I solved the issue, and its really my bad for not providing a more specific case information and made you guys confused.
I was using socialite and called _myFunction() inside the third party's callback..
After all, the problem was the socialite's google callback, instead of placing the return redirect()->route('profile', [$user->id]) inside _myFunction(), what I did was transfer it to the callback function.
So it looked like this now...
private $to_pass_user_id;
public function handleGoogleCallback()
{
try {
$user = Socialite::driver('google')->user();
$this->_myFunction($user);
return redirect()->route('profile', [$this->to_pass_user_id]);
} catch (Exception $e) {
dd($e->getMessage());
}
}
public function _myFunction($some_data) {
... my logic here
$this->to_pass_user_id = $some_value_from_the_logic
}

How to get the second argument from route in laravel

I am trying to get the second argument from the route in laravel from the following code.
web.php
Route::get('users/{name}/forksnippets/{name2}','Forksnippet#viewforksnippet');
controller
public function viewforksnippet($slug){
dd($slug);
}
getting name here as result
Just add the second argument to the method of the controller.
public function viewforksnippet($slug, $name2)
{
dd($slug, $name2);
}
public function viewforksnippet($name, $name2)
{
dd($name2);
}
Please try this ex

Automatically Load/Show Laravel View File

I am thinking of any techniques of autoloading the view files according to url.
For example:
public function addProducts()
{
return view('admin.addProducts');
}
public function editProducts()
{
return view('admin.editProducts');
}
public function allProducts()
{
return view('admin.allProducts');
}
Here, the Controller's method name is identical to view file name. So, I am thinking, if it is possible to load the view files without writing same kind of method again and again.
Enlighten me.
If your route only needs to return a view, you may use the Route::view method.
For example:
Route::view('/welcome', 'welcome');
Route::view('/welcome', 'welcome', ['name' => 'Taylor']);
read more here
It's the call PHP magic, man. https://repl.it/#Piterden/PHP-call-magic?language=php
public function __call($method, $parameters)
{
if (str_contains($method, 'Product')) {
return view("admin.{$method}");
}
}
btw, it's not a good practice for controller.

How to get a value in controller from get method and return it back to another view?

The problem looks basic but it is really painful!
I'm using get method and getting value in controller and I want the same value to return in another view.
How can I do that???
Please help!!!
This is my function from controller:
public function guest(){
if (Input::get('Cash On Delivery')){
$get = Input::get('Cash On Delivery');
return Redirect::to('guest/guestview/'.$get);
}
Well, with regards to your answer, using $_REQUEST directly is not Laravel's way of doing things :(
I believe this is better
public function guest(Request $request)
{
if ($request->payment_method == ('Cash On Delivery'))
{
return view('guest/guestview', ['guest'=>$request->payment_method]);
}
}
Ok Guys, I figured it out,
Just do this below.
public function guest(Request $request){
if ($request->payment_method == ('Cash On Delivery')){
$get = $_REQUEST['payment_method'];
return view('guest/guestview', compact('get'));
}

The return of view() in Laravel?

I am just learning Laravel 5.1 framework, I find a puzzling problem.
First, I create a model named 'Page', then I create a controller named 'HomeController', the method code is following:
public function index()
{
return view('home')->withPages(Page::all());
}
I cannot find 'withPages()' function, so I find helper function view() return \Illuminate\View\View, so I find 'vendor/laravel/framework/src/Illuminate/View/View.php', there is a "__call()", so I get it.
But I try to delete this function, my site is still normal.
did I find the wrong place? I am very puzzled.
... there is a "__call()", so I get it. But I try to delete this function, my site is still normal. did I find the wrong place? I am very puzzled.
Probably.
Laravel 'compiles' all it's core classes into a single file as a performance optimisation.
Try running php artisan clear-compiled and your site should start failing.
This is how I would do it -
public function index()
{
return view()->with('pages', Page::all());
}
If you want to use withPages method, you need to have a variable $pages set in the method.
So your method would look like:
public function index()
{
pages = Page::all();
return view('home')->withPages($pages);
}
Other two options:
public function index()
{
return view('home')->with('pages', Page::all());
}
or
public function index()
{
pages = Page::all();
return view('home')->with(compact('pages));
}
You can use any of these methods.

Resources