Viewed   95 times

i'm stuck at this very basic form, that i could not accomplish, which i want to build a search form with an text input, and two select controls, with a route that accept 3 parameters, the problem that when the i submit the form, it map the parameters with the question mark, not the Laravel way,


{{ Form::open(['route' => 'search', 'method' => 'GET'])}}
    <input type="text" name="term"/>
    <select name="category" id="">
        <option value="auto">Auto</option>
        <option value="moto">Moto</option>
    {{ Form::submit('Send') }}
{{ Form::close() }}


    Route::get('/search/{category}/{term}', ['as' => 'search', 'uses' => '[email protected]']);

When i submit the form it redirect me to


How can i pass these paramters to my route with the Laravel way, and without Javascript ! :D



The simplest way is just to accept the incoming request, and pull out the variables you want in the Controller:

Route::get('search', ['as' => 'search', 'uses' => '[email protected]']);

and then in [email protected]:

class SearchController extends BaseController {

    public function search()
        $category = Input::get('category', 'default category');
        $term = Input::get('term', false);

        // do things with them...

Usefully, you can set defaults in Input::get() in case nothing is passed to your Controller's action.

As joe_archer says, it's not necessary to put these terms into the URL, and it might be better as a POST (in which case you should update your call to Form::open() and also your search route in routes.php - Input::get() remains the same)

Monday, September 5, 2022

Instead of changing input names, just Override trait function and call it from the overriden function...

With this done, we can store a session value that tell us from where the auth attempt is coming from login or register form!

    use AuthenticatesUsers, RegistersUsers {
    AuthenticatesUsers::redirectPath insteadof RegistersUsers;
    AuthenticatesUsers::getGuard insteadof RegistersUsers;
    login as traitLogin;
    register as traitRegister;

// Override trait function and call it from the overriden function
public function login(Request $request)
    //Set session as 'login'
    Session::put('last_auth_attempt', 'login');
    //The trait is not a class. You can't access its members directly.
    return $this->traitLogin($request);

public function register(Request $request)
    //Set session as 'register'
    Session::put('last_auth_attempt', 'register');
    //The trait is not a class. You can't access its members directly.
    return $this->traitRegister($request);

and in your View.blade file just check your errors with your Session value ...

<div class="form-group{{ $errors->has('email') && Session::get('last_auth_attempt') == 'login' ? ' has-error' : '' }}">
    <label class="col-md-4 control-label">E-Mail</label>

    <div class="col-md-6">
        <input type="email" class="form-control" name="email" value="{{ old('email') }}">

        @if ($errors->has('email') && Session::get('last_auth_attempt') == 'login')
            <span class="help-block">
                <strong>{{ $errors->first('email') }}</strong>

With this you can check if button pressed is from login ou register button

Wednesday, October 5, 2022

I found a solution but I don't think this is the right place to write it. I added a simple line of code on the ConnectorLaravel5 class.

public function __construct($module)
    $this->module = $module;

    $components = parse_url($this->app['config']->get('app.url', 'http://localhost'));
    $host = isset($components['host']) ? $components['host'] : 'localhost';

    parent::__construct($this->app, ['HTTP_HOST' => $host]);

    // Parent constructor defaults to not following redirects

    // Added to solve the problem of overriding the request method

This solves my problem.

Friday, September 23, 2022

Use the -v switch to pass in variables.

sqlcmd -v varMDF="C:devSAMPLE.mdf" varLDF="C:devSAMPLE_log.ldf"

Then in your script file

( NAME = N'SAMPLE_log', FILENAME = N'$(varLDF)' , SIZE = 29504KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
Friday, December 2, 2022

To add multiple parameters, you need to seperate them with a comma:

Route::group(['middleware' => ['role_check:Normal_User,Admin']], function() {
        Route::get('/user/{user_id}', array('uses' => 'UserControlle[email protected]', 'as' => 'showUserDashboard'));

Then you have access them to in your middleware like so:

public function handle($request, Closure $next, $role1, $role2) {..}

The logic from there is up to you to implement, there is no automatic way to say "OR".

Wednesday, September 21, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :