1
I created a CRUD with Modal is working all right but I created request form data display, queries with BD all within Routes, I do not think very cool would like to pass these features to the Controller to do but it is not working is appearing error:
Today the CRUD is like this:
app Routes.php
use App\Task;
use Illuminate\Http\Request;
Route::get('/admin', function () {
$tasks = Task::all();
return View::make('admin')->with('tasks',$tasks);
});
Route::get('/tasks/{task_id?}',function($task_id){
$task = Task::find($task_id);
return Response::json($task);
});
Route::post('/tasks',function(Request $request){
$task = Task::create($request->all());
return Response::json($task);
});
Route::put('/tasks/{task_id?}',function(Request $request,$task_id){
$task = Task::find($task_id);
$task->task = $request->task;
$task->description = $request->description;
$task->save();
return Response::json($task);
});
Route::delete('/tasks/{task_id?}',function($task_id){
$task = Task::destroy($task_id);
return Response::json($task);
});
Then I created this way for the Controller to do the job but it’s not working
app Routes.php
use App\Task;
use Illuminate\Http\Request;
Route::controller('/admin', 'TaskController');
controllers Taskcontroller.php
namespace App\Http\Controllers;
use App\Task;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class TaskController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function getindex()
{
$tasks = Task::all();
return View::make('admin')->with('tasks',$tasks);
}
public function getAdd($task_id)
{
$task = Task::find($task_id);
return Response::json($task);
}
public function postAdd(Request $request)
{
$task = Task::create($request->all());
return Response::json($task);
}
public function getEdit($task_id)
{
$task = Task::find($task_id);
return Response::json($task);
}
public function postEdit(Request $request, $task_id)
{
// $task = $request->except('_token');
$task = Task::find($task_id);
$task->task = $request->task;
$task->description = $request->description;
$task->save();
return Response::json($task);
}
public function getDelete($task_id)
{
$task = Task::destroy($task_id);
return Response::json($task);
}
}
I took a look at the source code of
Laravel
and, if I’m not mistaken,,Route::controller
was deprecated. Can be removed in future versions.– Wallace Maxters
https://github.com/laravel/framework/commit/98fb934b669c45aad6ca118d4fe29f2bf141d7f6
– Wallace Maxters