Is it possible to capture the current url in the blade view?

1

I would like to capture the url example, /user/** (everything starting with / user), I'm using laravel and blade, using Request :: url () I get localhost:8000 but I need something that can capture the routes. Thank you

    
asked by anonymous 15.08.2016 / 15:40

2 answers

1

To get the url in the view you can do:

<p>{{Request::url()}}</p>

To check if the second segment of the url has "user":

@if(explode('/', Request::url())[3] == 'user')
    // tem '/user'
@endif

Sending this from the controller might be a better idea:

public function logout(Request $request) {
    if($request->segments()[0] == 'user') {
        // url tem como primeiro segmento "user"
    }
}

Still other possible solution , without having tested, sorry if it does not work:

if (Request::is('user/*'))
{
     // code
}
    
15.08.2016 / 15:48
0

I do this on the blade:

//http://localhost:8000/user/teste

//Pegar o primeiro que é "user"
Request::segment(1)

//Pegar o segundo é "teste"
Request::segment(2)

It already ignores the default URL and takes the route directly.

In case to check if it starts with "user" you would do so on the blade:

{{ Request::segment(1) == 'user' ? 'verdadeiro' : 'falso' }}

Or:

@if(Request::segment(1) == 'user')
    //Suas instruções aqui
@endif
    
15.08.2016 / 16:30