|
<?php |
|
|
|
namespace Alpha\Library\Http\Controllers\API; |
|
|
|
use App\Http\Controllers\Controller; |
|
use Alpha\Library\Http\Requests\Authors\AuthorRequest; |
|
use Alpha\Library\Model\Author; |
|
use Illuminate\Http\Response; |
|
|
|
class AuthorsController extends Controller |
|
{ |
|
/** |
|
* Display a listing of the resource. |
|
* |
|
* @return \Illuminate\Http\Response |
|
*/ |
|
public function index() |
|
{ |
|
return response()->json(Author::all(), Response::HTTP_OK); |
|
} |
|
|
|
/** |
|
* Store a newly created resource in storage. |
|
* |
|
* @param App\Http\Requests\Authors\AuthorRequest $request |
|
* @return \Illuminate\Http\Response |
|
*/ |
|
public function store(AuthorRequest $request) |
|
{ |
|
$input = $request->only(['name', 'description', 'status', 'joined_date']); |
|
$author = Author::create($input); |
|
return response()->json(['success' => true, 'data' => $author], Response::HTTP_CREATED); |
|
} |
|
|
|
/** |
|
* Display the specified resource. |
|
* |
|
* @param int $id |
|
* @return \Illuminate\Http\Response |
|
*/ |
|
public function show($id) |
|
{ |
|
return response()->json(Author::findOrFail($id)); |
|
} |
|
|
|
/** |
|
* Update the specified resource in storage. |
|
* |
|
* @param App\Http\Requests\Authors\AuthorRequest $request |
|
* @param int $id |
|
* @return \Illuminate\Http\Response |
|
*/ |
|
public function update(AuthorRequest $request, $id) |
|
{ |
|
$input = $request->only(['name', 'description', 'status', 'joined_date']); |
|
$author = Author::findOrFail($id); |
|
$author->update($input); |
|
return response()->json(['success' => true, 'data' => $author], Response::HTTP_OK); |
|
} |
|
|
|
/** |
|
* Remove the specified resource from storage. |
|
* |
|
* @param int $id |
|
* @return \Illuminate\Http\Response |
|
*/ |
|
public function destroy($id) |
|
{ |
|
$author = Author::findOrFail($id); |
|
$author->delete(); |
|
return response()->json(['success' => true, 'data' => null], Response::HTTP_NO_CONTENT); |
|
} |
|
|
|
/** |
|
* Display a dropdown with id and name field of the resource. |
|
* |
|
* @return \Illuminate\Http\Response |
|
*/ |
|
public function dropdown() |
|
{ |
|
return response()->json(Author::where('status', Author::STATUS_ACTIVE)->get()->pluck(['id', 'name']), Response::HTTP_OK); |
|
} |
|
} |
|
?> |