0
votes

I use laravel 5.6 and I'm beginner in this framework, I want to stock in my database in publicite table "name","path","url" of all publicites, I make a modal and controller and I add my controller to api.php in route and I get this error

Too few arguments to function App\Http\Controllers\PubliciteController::stockpath(), 0 passed and exactly 1 expected

this is my controller : "PubliciteController":

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\publicite;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
use Config;
use Artisan;

class PubliciteController extends Controller
{
    //enregistre les path des images
    public function stockpath ($request){
        $input = $request->all();
        $validator =    Validator::make($input, [
            'name'=> 'required',
            'url'=> 'required',
            'path'=> 'required'
        ] );

        if ($validator -> fails()) {
            # code...
            return $this->sendError('error validation', $validator->errors());
        }

        $ads = ads::create($input);
        return $this->sendResponse($ads->toArray(), 'Ads created succesfully');
    }
}

this is my model publicite:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Publicite extends Model
{
    protected $fillable = [
        'name','url', 'path',
    ];
}

and this is my route:

Route::post('publicite', 'PubliciteController@stockpath');

where is it my falut , what's exepected I use post man and I get this error

1

1 Answers

2
votes

Please try to read manual next time before ask question.

https://laravel.com/docs/5.7/requests

There is written:

To obtain an instance of the current HTTP request via dependency injection, you should type-hint the Illuminate\Http\Request class on your controller method. The incoming request instance will automatically be injected by the service container:

Which means that not

public function stockpath ($request){

but

public function stockpath (Request $request){