Controller method not found after adding an extra parameter - laravel-5

I have declared implicit route like below:
Route::controller("api/public/rental/models", 'Api\Rental\ModelsController');
public function getFees(Request $requ, $pick_up_location, $drop_off_location, $start_datetime, $end_datetime,$type)
{
}
It is working fine. But if I add any extra parameter further like below
public function getFees(Request $requ, $pick_up_location, $drop_off_location, $start_datetime, $end_datetime,$type,$class)
{
}
I am getting following error:
NotFoundHttpException in Controller.php line 269: Controller method
not found.
Is there any limitation? How to resolve this issue?

Related

Laravel: Missing Argument error on a POST

I keep getting the error "Missing argument 1 for App\Http\Controllers\Users::deleteMobileAssets()" . I am making a call from my frontend with Vue. When I check the headers, it seems correct but I'm not sure what is causing the error. I've tried wrapping imageType in brackets too: {imageType: imageType} but still same error.
deleteImage(imageType) {
axios.post('/delete-mobile-assets', imageType);
}
public function deleteMobileAssets($imageType)
{
}
POST data is included in the body of the request that way you are getting Missing argument 1. Try this
deleteImage(imageType) {
axios.post('/delete-mobile-assets', {imageType:imageType});
}
public function deleteMobileAssets(Request $request)
{
$request->imageType
}
Or if you want to implement DELETE method. have a look Delete Method in Axios, Laravel and VueJS

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

How can I solve NotFoundHttpException No query results for model on laravel?

My code like this :
return redirect()->route('camp.don.summary', ['id'=>$dons->id]);
If the code executed, it will call route
The route like this :
Route::prefix('camp')->group(function(){
...
Route::prefix('don')->group(function(){
...
Route::get('summary/{id}', 'CampController#summary')->name('camp.don.summary');
});
});
Then the route call controller
The controller like this :
public function summary($id)
{
dd($id);
return view('camp.don.summary.index');
}
On the browser, the url seems like this :
http://myapp.dev/camp/don/summary/31
And the content exist error like this :
(2/2) NotFoundHttpException No query results for model
[App\Models\Camp] 31
How can I solve this error?
Seems my process is still wrong
Perhaps you have configured explicit route model binding
Check your RouteServiceProvider class

Laravel 4: get url parameter from controller

I'm new to laravel 4 and I'm currently having the following problem:
In my routes.php I have the line:
Route::get('maps/{map_type}', 'MapsController#loadMaps');
And in my MapsController I'd like to get the {map_type} to use it.
So my question: How can I retrieve map_type in my Controller?
Your first argument in your loadMaps method is your map type.
public function loadMaps($map_type) {
return $map_type;
}
Take a look at the first two code snippets on http://laravel.com/docs/controllers.
Controllers receive parameters as parameters in the called function:
class MapsController extends BaseController {
public function loadMaps($map_type) {}
}
Check http://laravel.com/docs/controllers#basic-controllers for more info

Extending Form Validation in Codeigniter call to a member function on a non-object error

I know this has been asked before, and I've looked through every answer posted, but to no avail. Basically, I am trying to extend the Codeigniter form validation library on a CI2+ project, but every single time I get the error:
Fatal error: Call to a member function get_errors_array() on a non-object
Below is my code:
application/core/CB_Form_validation.php
class CB_Form_validation extends CI_Form_validation{
function __construct($rules = array()) {
parent::__construct($rules);
log_message('debug', "CB_Form_validaiton class initialized");
}
public function get_errors_array() {
return $this->_error_array;
}
}
and then in my ajax file I have the construct etc.
public function save(){
if($this->form_validation->run() == FALSE){
}
}
and inside that if statement I have tried the following:
echo $this->form_validation->get_errors_array();
echo $this->cb_form_validation->get_errors_array();
echo get_errors_array();
I have also tried placing the CB_Form_validation.php in application/libraries as well. Just as well, I have also tried this in my construct of my ajax controller
$this->load->library('CB_Form_validation');
$this->load->library('core/CB_Form_validation');
And I have set CB_ as my custom class prefix
Turns out that to fix this, you should do the following:
Move your custom form validation class to the application/libraries folder
You can keep the construct of your custom class how it is
Use $this->form_validation->method() to access the function you would like
As long as your loading the form_validation library, you don't need to perform $this->load->library('custom_class') because CI picks up on your custom prefix anyways
Hope this helps someone

Resources