I am using laravel 8
and run it on a apache/ubuntu 20
server
My routes look like the following:
web.php
Route::get('/', 'IndexController@index');
Route::get('/company/{symbol}', 'CompanyController@index');
In my .env
file the APP_URL
looks like the following:
APP_URL=http://localhost/laravel_app/public
I can reach my base url /
the following way:
http://localhost/laravel_app/public/
When I go from /
to another detail url f.ex. /company/AAPL
, I get:
Within my base ( /
) url's blade file index.blade.php
file the code to click the link looks like the following:
@foreach ($company as $i)
<tr>
<th scope="row"><a href="/company/{{$i->symbol}}">{{$i->name}} ({{$i->symbol}})</a></th>
<td>{{$i->date}}</td>
...
</tr>
@endforeach
Why is the Route /company/{symbol}
not mapped correctly?
Any suggestions what I am doing wrong?
I appreciate your replies!
use function url it will create valid url
url("/company/{{$i->symbol}}")
route function is very help full in url creation give route name
Route::get('/company/{symbol}', 'CompanyController@index')->name('company.page');
when ever url required to print
route('company.page', ['symbol' => $i->symbol])
it will return valid url
When you put / at the beginning of the path, it will go to root of yor project location | domain. You must set it like:
href="company/{{$i->symbol}}"
or with url
helper
url('company' . $i->symbol)
But a better way would be naming the routes like:
// add name to your route
Route::get('/company/{symbol}', 'CompanyController@index')->name('company.index');
// call the route helper to return the url
route('company.index', ['symbol' => $i->symbol]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.