/** * Retrieve objects */ Route::get('api/{model}/{id?}', array('before' => 'snapi_auth', function ($model, $id = false) { $model = new $model(); return false !== $id ? Response::json($model->find($id)) : Response::json($model->all()); })); /** * Update objects */ Route::post('api/{model}/{id}', array('before' => 'snapi_auth', function ($model, $id) { $model = new $model(); $model = $model->find($id); if (!$model->update(Input::except('api_key'))) { // uh-oh! return Response::json(array('errors' => Ardent::errors()->all(), 'data' => $model), 409); } else { // success! return Response::json(array('message' => 'updated', 'data' => $model), 201); } })); /** * Delete objects */ Route::delete('api/{model}/{id?}', array('before' => 'snapi_auth', function ($model, $id) { $model = new $model(); $result = false !== $id ? $model->find($id)->delete() : $model->delete(); if ($result) { return Response::json(array('message' => 'deleted'), 200); } else { return Response::json(array('errors' => 'error'), 409);
/** * Boot Method */ public static function boot() { parent::boot(); // self::created(function(){ // Cache::tags('ReportEager')->flush(); // }); // self::updated(function(){ // Cache::tags('ReportEager')->flush(); // }); // self::deleted(function(){ // Cache::tags('ReportEager')->flush(); // }); }
/** * Receives the invalid model and sets the {@link model} and {@link errors} properties. * @param Ardent $model The troublesome model. */ public function __construct(Ardent $model) { $this->model = $model; $this->errors = $model->errors(); }
/** * Boot Method */ public static function boot() { parent::boot(); self::creating(function ($data) { $data->user_id = Auth::user()->id; }); // self::created(function () { // Cache::tags('Upload')->flush(); // }); // self::updated(function () { // Cache::tags('Upload')->flush(); // }); // self::deleted(function () { // Cache::tags('Upload')->flush(); // }); self::deleting(function ($data) { File::deleteDirectory($data->path); return true; }); }