mardi 19 février 2019

how I can pass the token to header not in body :laravel 5.6

I use post man to test my api , So when I send the token in header I get token not provided , but when i pass it in raw in json format I get a succes result, So I want to get succes reult when I pass my token in header

How I can make this change

This my Postcompanies controller

class CompaniesController extends Controller
{
    public function index(Request $request)
    {
        # code...
        //  $Ads = ads::all();
        //  return $this->sendResponse($Ads->toArray(), 'Ads read succesfully');
        // This is the name of the column you wish to search
        $input = $request->all();
        $validator =    Validator::make($input, [
            'user_id'=> 'required'
        ] );

        $Companies = Companies::where('user_id','=', $request->user_id)->first();

        return response()->json(['Companies'=>$Companies]);
    }

    public function stockcompanies (Request $request){
        $input = $request->all();

        $validator =    Validator::make($input, [
            'title'=> 'required',
            'description'=> 'required',
            'logo_path'=> 'image|nullable|max:1999'
        ] );


        $user_id = Auth::id();
        if($request->hasFile('logo_path')){
            // Get filename with the extension
            $filenameWithExt = $request->file('logo_path')->getClientOriginalName();
            // Get just filename
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            // Get just ext
            $extension = $request->file('logo_path')->getClientOriginalExtension();
            // Filename to store
            $fileNameToStore= $filename.'_'.time().'.'.$extension;
            // Upload Image
            $path = $request->file('logo_path')->storeAs('public/cover_images', $fileNameToStore);
        } else {
            $fileNameToStore = 'noimage.jpg';
        }
        if ($validator -> fails()) {
            # code...
            return response()->json($validator->errors());
        }

        //$Cards = CreditCards::create($input,$user_id);
        $companies = Companies::create([
            'title' => $request->get('title'),
            'description' => $request->get('description'),
            'logo_path' => $fileNameToStore,
            'user_id' => $user_id
        ]);
        return response()->json(['Companies'=>$companies]);
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire