I am running this command for model, migration, resource controller.
`php artisan make:model QuestionAnswer -mc -r` ..
Laravel give me in Resource Controller
public function show(QuestionAnswer $questionAnswer) {
// return $questionAnswer;
}
public function edit(QuestionAnswer $questionAnswer) {
// return $questionAnswer;
}
public function update(Request $request, QuestionAnswer $questionAnswer){
// return $questionAnswer;
}
if I write in web.php
Route::resource('question-answer','QuestionAnswerController');
or
Route::resource('questionAnswer','QuestionAnswerController');
or
Route::resource('question_answer','QuestionAnswerController');
laravel resolve route model binding...
that means....
Example as a
public function edit(QuestionAnswer $questionAnswer)
{
return $questionAnswer;
}
$questionAnswer
return object for this url {{route('admin.question-answer.edit',$questionAnswer->id)}}
but if I write in web.php
Route::resource('faq','QuestionAnswerController');
laravel can not resolve route model binding...
that means.. $questionAnswer
return null for this url {{route('admin.faq.edit',$questionAnswer->id)}}
also in show
and update
function $questionAnswer;
return null...
for working as a faq
url.. i need change in edit function
variable($faq
) . or Route::resource('faq','QuestionAnswerController')->parameters(['faq' => 'questionAnswer']);
I
But These three url questionAnswer
,question-answer
,question_answer
by default work...
I check it on "laravel/framework": "^6.0" (LTS)
Question
is there possible way to find out what exact url I will write ? .. like question-answer
.. or is there any command line ...
after running auth command .. php artisan route:list
command give us all route list.. and when I make model Category
laravel create table name categories
and follow grammar rules
Actually Laravel has got Naming Convection Rules In its core.
These Convictions make it to default binding database_tables to model, model to controllers ....
if you want, you can tell your custom parameters but if you dont, The Laravel uses its own default and searching for them.
for example: if you have a model named bar, laravel look for a table named plural bars . and if you dont want this behave, you can change this default by overriding the *Model
s*
$table_name` attribute for your custom parameter.There are some Name Convection Rules Like :
tables are plural and models are singular : its not always adding s (es) in trailing. sometimes it acts more complicate. like : model:person -> table: people
pivot table name are seperate with underline and should be alphabetic order: pivot between fooes and bars table should be bar_foo (not foo_bar)
table primary key for Eloquent find or other related fucntion suppose to be singular_name_id : for people table : person_id
if there are two-words name in model attribute, all of these are Alias : oneTwo === one_two == one-two
check this out:
all of this return
"hello"
:there is a page listing laravel naming conventions :
https://webdevetc.com/blog/laravel-naming-conventions/