I created a CRUD with Modal is working everything right but I created form request data view, queries with BD all inside Routes, I do not think very cool would like to pass these features to the Controller to do but is not working is appearing the error:
Today CRUD looks 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 so that the Controller does the work but it is 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);
}
}