Skip to content

Instantly share code, notes, and snippets.

@luckys383
Created June 4, 2019 08:18
Show Gist options
  • Save luckys383/253e2b9681f261e2f09a3ee859464db0 to your computer and use it in GitHub Desktop.
Save luckys383/253e2b9681f261e2f09a3ee859464db0 to your computer and use it in GitHub Desktop.
Repository Pattern: CRUD
<?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