mardi 6 mars 2018

I want to send a variable from a Controller to a Trait on Laravel

I have a controller that store the data. This use a form Request and after Show the messages on a trait. I am using the same trait on 3 API but i want to know if is posible send/add to the json/array a Custom Message for each API. For example if Category created (Category created successfull o Product Created Successfull) according the api. This is my Store on my controller

    public function store(StoreCategory $request)
{
    $data = request()->all();
    $newCategory = Category::create($data);    
    return $this->respondCreated(new CategoryResource($newCategory)); 
}

I am using CategoryResource like Resource And this is my trait

    public function respondCreated($data)
{
    return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond($data
    ->response()      
    );
}
    public function respond($data, $headers = [])
{
    $response = $data;
    return $response->setStatusCode($this->statusCode);        
}

Is Possible add a custom message per Api Request? May be can i pass a Variable from my controller and after add the custom message add the variable to the array?

Best Regards Sorry my english is not good



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2oMsPDk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire