This is my first question in this forum so please be patient to me ;) I'm making a blog using Laravel and I have a page with a view of all articles inside my database enter image description here
Last column is "Action" column whet after hit the button you can see single article. The problem is to show each content (title,subtitle etc.) i must create loooong UrL like this http://127.0.0.1:8000/article/Test/Test/test/2020-05-08%2016:00:00
Is there any chance to cut URL to be like that: http://127.0.0.1:800/article/Test and still have all content?
档案
web.php 路线:: get('article / {title_article} / {subtitle_created} / {text_article} / {created_at}','ReadController @ index');
控制者
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Article;
class ReadController extends Controller
{
public function index($title_article,$subtitle_article,$text_article,$created_at)
{
return view('article',compact('title_article','subtitle_article','text_article','created_at'))->with('title','Artykuł');
}
}
You should use the
primary key
(probably an incrementing id) of your database object (App\Article) to identify the object. Laravel has a wonderful function to automatically convert theprimary key (id)
in the route to aneloquent model
.在您的情况下:
Route::get('article/{article}','ReadController@index');
和
public function index(Article $article) { ... }
我希望这可以帮助你。如果您不了解其中的一部分,请随时提出:)