Skip to content

Instantly share code, notes, and snippets.

@lagbox
Created April 16, 2016 21:50
Show Gist options
  • Save lagbox/a61f4f0972d0a282c8235d45f2695814 to your computer and use it in GitHub Desktop.
Save lagbox/a61f4f0972d0a282c8235d45f2695814 to your computer and use it in GitHub Desktop.
<?php
Route::post('test', 'TestController@store');
<?php
namespace App\Http\Controllers;
use App\Http\Requests\TestRequest;
class TestController extends Controller
{
public function __construct()
{
$this->middleware('test');
}
public function store(TestRequest $request)
{
dd($request->all());
}
}
<?php
namespace App\Http\Middleware;
use Closure;
class TestMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$request->replace(['test' => 'testing']);
return $next($request);
}
}
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class TestRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/*
public function validate()
{
dd($this->all());
}
*/
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'content' => 'required'
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment