Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to a route in laravel 5 by using href tag if I'm not using blade or any template?

Route::get('/page','UserController@view page'); 

is my route.

I have a list with href tag and I want to redirect to this route.

<ul>
    <li><a href="">how it works</a></li>
</ul>

I am not using blade or any other templates.

like image 262
Jasmel Pc Avatar asked Dec 04 '15 05:12

Jasmel Pc


People also ask

How do I pass a route in href?

You can pass two variables to anchor tag (HREF) in Laravel. You can call the url() helper function or you can call the route method with multiple arguments in Laravel view to pass the variable values to anchor tag in Laravel.

What is the difference between url and route in Laravel?

For a start it is using a named route. This means that the link between the form and its controller are not dictated by the url that the user sees. The next advantage is that you can pass additional parameters into the route helper and it will put those in the correct place in the form action.


3 Answers

In you app config file change the url to localhost/example/public

Then when you want to link to something

<a href="{{ url('page') }}">Some Text</a>

without blade

<a href="<?php echo url('page') ?>">Some Text</a>

like image 166
chanafdo Avatar answered Oct 07 '22 18:10

chanafdo


In addition to @chanafdo answer, you can use route name

when working with laravel blade

<a href="{{route('login')}}">login here</a> with parameter in route name

when go to url like URI: profile/{id} <a href="{{route('profile', ['id' => 1])}}">login here</a>

without blade

<a href="<?php echo route('login')?>">login here</a>

with parameter in route name

when go to url like URI: profile/{id} <a href="<?php echo route('profile', ['id' => 1])?>">login here</a>

As of laravel 5.2 you can use @php @endphp to create as <?php ?> in laravel blade. Using blade your personal opinion but I suggest to use it. Learn it. It has many wonderful features as template inheritance, Components & Slots,subviews etc...

like image 27
sumit sharma Avatar answered Oct 07 '22 19:10

sumit sharma


Please consider this solution whith laravel blade for edit an item from list

            <a href="{{ url('players' , [ 'id' => $player->id ]) }}/edit"
               class="btn btn-primary" role="button">Varia</a>
        </div>
    </div>
    @endforeach
like image 40
Ottavino Gnata Avatar answered Oct 07 '22 20:10

Ottavino Gnata