Isn't it this->app->instance(...) ??
How to Pass arguments to function in test
I have the following function to test:
public function save(ServiceRequest $request,
User $usuario,
Service $service = null);
In my routes.php I have
Route::post('service/create', 'ServiceController@save');
In my RouteServiceProvider I have:
$router->model('service', 'App\Service');
There are no service key in Route::post('service/create', 'ServiceController@save'); ( I use service key in other route). But then I check in ServiceController $service and it is not equals to null but in fact, there is a service elloquent model...
how do I pass arguments to avoid it? I tried
$this->actingAs($user);
$this->post('service/create', ['_token' => csrf_token(), 'service' => null])
->withSession(['status' => 'The execution was a success!'])
->seePageIs('service/create')
;
But it didn't work.
The laravel way of doing things is to have separate method for store and update. You should keep this convention.
Then you should follow the rest convention too, it simplify things :
- Show the create form for a model (ex : an article) : GET /articles/create => ArticlesController@create
- Store a model : POST /articles => ArticlesController@store
- Edit a model : GET /articles/{article_id}/edit => ArticlesController@edit
- Update a model : PUT /articles/{article_id} => ArticlesController@update
And I think you should not pass any parameter named service when calling the route, it default to null if not present anyway.
Please or to participate in this conversation.