Created
June 4, 2019 08:18
-
-
Save luckys383/253e2b9681f261e2f09a3ee859464db0 to your computer and use it in GitHub Desktop.
Repository Pattern: CRUD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Repositories; | |
use App\Models\Post; | |
use App\Repositories\AppRepository; | |
use Illuminate\Http\Request; | |
class PostsRepository extends AppRepository | |
{ | |
protected $model; | |
public function __construct(Post $model) | |
{ | |
$this->model = $model; | |
} | |
/** | |
* set payload data for posts table. | |
* | |
* @param Request $request [description] | |
* @return array of data for saving. | |
*/ | |
protected function setDataPayload(Request $request) | |
{ | |
return [ | |
'title' => $request->input('title'), | |
'author_id' => $request->user()->id, | |
'description' => $request->input('description'), | |
'status' => $request->input('status'), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment