Check if laravel model got saved or query got executed

后端 未结 4 1314
情歌与酒
情歌与酒 2020-12-01 04:11

I\'ve seen alot of people using this way to check if a laravel model got saved. So now I wonder if it is a safe way.

And also can I check if the queries bellow got e

4条回答
  •  春和景丽
    2020-12-01 04:52

    /**
     * Store a newly created country in storage.
     *
     * @url /country
     * @method POST
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function store(Request $request)
    {
      # Filer & only get specific parameters.
      $request = $request->only('code', 'name', 'status');
    
      # Assign login user(Auth Control).
      $request['created_by'] = Auth::user()->id;
    
      # Insert data into `countries` table.
      $country = Country::create($request);
    
      if(!$country)
        throw new Exception('Error in saving data.');
    }
    

提交回复
热议问题