【问题标题】:add links for blade php pages添加刀片 php 页面的链接
【发布时间】:2019-02-22 08:48:52
【问题描述】:

我为我的应用程序开发了几个页面。现在我需要为这些页面添加链接。直到现在我通过 url 浏览打开这些页面。

我的 web.php 页面

// for books
Route::get('/book','BookController@create');
Route::post('/book','BookController@store');
Route::get('/book/{id}','BookController@edit');
Route::patch('/book/{id}', 'BookController@update');

// for ordered books
Route::get('/order','OrderedBookController@create');
Route::post('/order','OrderedBookController@store');
Route::get('/billSearch','OrderedBookController@searchBill');
Route::post('/billSearch','OrderedBookController@billPay');
Route::post('/billSearch/{id}', 'OrderedBookController@pay');

// for Books Out
Route::get('/booksout','BooksOutController@create');
Route::post('/booksout','BooksOutController@store');

路线对应的页面列表

book.blade.php
edit.blade.php
booksin.blade.php
booksout.blade.php

浏览这些页面的本地主机url是::

http://127.0.0.1:8000/book
http://127.0.0.1:8000/order
http://127.0.0.1:8000/billSearch // for Route::get('/billSearch','OrderedBookController@searchBill');
http://127.0.0.1:8000/booksout

由于我是通过路由而不是页面浏览我的页面,如何在我的网络应用程序中创建链接?

【问题讨论】:

  • 与任何其他链接一样:<a href="/book">Book</a>.
  • 最好的方法是创建命名路由并在 href="{{route('route_name')}}" 中使用这个名称

标签: php laravel laravel-5 laravel-blade


【解决方案1】:

使用route()url() 函数。

例如在刀片视图中:

<a href="{{ route('book') }}"></a>

更多内容请关注laravel docs

【讨论】:

    【解决方案2】:

    只需像这样插入您的路线:

    <a href="/book">Book</a> --> http://127.0.0.1:8000/book
    <a href="/billSearch ">Bill Search</a> --> http://127.0.0.1:8000/billSearch 
    

    【讨论】:

      【解决方案3】:

      你可以使用以下两种方式之一在 laravel 中链接不同的页面

      1:通过在刀片 href 中包含您在路由中定义的 url

       Route::post('/billSearch', 'OrderedBookController@pay');
      

      因此在您的刀片链接中

      <a href="/billSeach"> </a>
      

      2:通过使用路线的名称

       Route::post('/billSearch', 'OrderedBookController@pay')->name('bill);
      

      因此在您的刀片视图中

      <a href="{{route('bill'}}"></a>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-01
        • 2018-02-28
        • 2016-07-11
        • 2020-08-26
        • 1970-01-01
        • 1970-01-01
        • 2011-10-31
        • 1970-01-01
        相关资源
        最近更新 更多