How to redirect to a route in laravel 5 by using h

2019-03-25 05:15发布

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.

2条回答
叛逆
2楼-- · 2019-03-25 05:47

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...

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-25 05:59

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>

查看更多
登录 后发表回答