Created
September 17, 2013 06:46
-
-
Save insign/6590813 to your computer and use it in GitHub Desktop.
Resource bug
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 | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register all of the routes for an application. | |
| It's a breeze. Simply tell Laravel the URIs it should respond to | |
| and give it the Closure to execute when that URI is requested. | |
| | |
*/ | |
Route::resource('/', 'HomeController'); | |
Route::group(array('before' => 'auth'), function() { | |
// Route::get('/items/destroy/{id}', 'ItemsController@destroy'); // It works | |
Route::resource('/items', 'ItemsController'); // not found exception | |
}); |
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 | |
class ItemsController extends BaseController { | |
/** | |
* Display a listing of the resource. | |
* | |
* @return Response | |
*/ | |
public function index() { | |
$data = [ | |
'items' => Item::where('user_id', '=', Auth::user()->id)->get(), | |
]; | |
return View::make('items.index', $data); | |
} | |
/** | |
* Show the form for creating a new resource. | |
* | |
* @return Response | |
*/ | |
public function create() { | |
return View::make('items.create'); | |
} | |
/** | |
* Store a newly created resource in storage. | |
* | |
* @return Response | |
*/ | |
public function store() { | |
$input = Input::all(); | |
$user_id = Auth::user()->id; | |
$validator = Validator::make($input, ['codigo' => "required|unique:items,codigo,NULL,id,user_id,$user_id"] | |
); | |
if ($validator->fails()) { | |
return Redirect::route('items.create')->withErrors($validator)->withInput(); | |
} | |
$item = new Item($input); | |
$item->ultimo_local = 'ainda desconhecido'; | |
$item->ultima_data = new DateTime(); | |
$user = User::find($user_id); | |
$user->items()->save($item); | |
return Redirect::route('items.index'); | |
} | |
/** | |
* 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) { | |
$item = ['test' => 2]; | |
// $item = Item::find($id); | |
return $item; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment