iT邦幫忙

DAY 23
0

初學laravel系列 第 23

鐵人賽 Day 23 RESTFUL 產生器

在laravel中有一個方式可以直接由指令產生出一些RESTFUL的CONTROLLER,

這個方法在你要產生一些資源管理的時候很方便,

你也可以選擇要產生那些FUNCTION,

接下來我們會教學說要如何去使用,

首先我們要使用以下指令去產生,

不過首先我們要先進入命令提示字元

打開後如下圖所示

我們使用cd 指令到目前laravel目錄底下,

鍵入你要產生的CONTROLLER類型如下,

php artisan controller:make PhotoController

接下來我們就可以看一下他產生的CONTROLLER了,

以下就是他產生的資料,

可是每個函數要怎麼驅動呢?

<?php

class PhotoController extends \BaseController {

/**

* Display a listing of the resource.

*

* @return Response

*/

public function index()

{

//

echo "123";

}

/**

* Show the form for creating a new resource.

*

* @return Response

*/

public function create()

{

//

echo "456";

}

/**

* Store a newly created resource in storage.

*

* @return Response

*/

public function store()

{

//

}

/**

* Display the specified resource.

*

* @param int $id

* @return Response

*/

public function show($id)

{

//

}

/**

* Show the form for editing the specified resource.

*

* @param int $id

* @return Response

*/

public function edit($id)

{

//

}

/**

* Update the specified resource in storage.

*

* @param int $id

* @return Response

*/

public function update($id)

{

//

}

/**

* Remove the specified resource from storage.

*

* @param int $id

* @return Response

*/

public function destroy($id)

{

//

}

}

可是只有這樣我們是無法使用的,

我們要到app\router.php中去設定對應的路由如下:

Route::resource('photo', 'PhotoController');

做完以上設定後

他每個函數驅動的方式,

如下表所示

這兩個模式詞,

當你要使用這兩個模式的時候你的FORM必須使用POST的方式,

並且在FORM中加入一個隱藏的欄位_method,

實際會如以下所示

<input name="_method" type="hidden" value="PUT">

這樣你才可以使用這兩個模式,

以上就是今天所介紹。


上一篇
鐵人賽 Day 22 Controller 簡易Restful 介紹
下一篇
鐵人賽 Day 24 schma 產生器
系列文
初學laravel30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言