Bu makale orijinal olarak bmf-tech.com adresinde yayımlanmıştır.
<p>Geliştirme sürecimizde Laravel ile birlikte React'ı frontend frameworkü olarak kullanıyoruz. Bir API tasarlamamız gerektiği için bu konuya göz atmaya karar verdik.</p>
<ul>
<li>Veri çıkışı yapan basit bir API oluşturmak için bir ResourceController oluşturun.</li>
<li>Halk API'ye açılmasını düşünüp, kimlik doğrulama middleware'ini uygulayın.</li>
</ul>
<ul>
<li>REST'i açıklayın.</li>
<li>API verilerini güncelleyin veya silin.</li>
<li>Ajax kullanarak veri çekin ve çıktı alın.</li>
</ul>
<p>Artisan sabahı erkenden başlar...<br/><code>php artisan make:controller HogeController --resource</code></p>
<p>Artisan işe geldiğinde, aşağıdaki gibi bir kontrolör oluşturur.<br/></p>
<div class="highlight js-code-highlight">
<pre class="highlight php"><code><?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class HogeController extends Controller
{
/
- Display a listing of the resource.
- @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}}
<p>Kısa bir şekilde API'yi oluşturalım. index() metodunu değiştirelim.<br/></p>
<div class="highlight js-code-highlight">
<pre class="highlight php"><code>
/
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$user = \Auth::user();
return \Response::json($user);
}

