dynamic url laravel
public function showBySlug($slug) {
$post = Post::where('slug','=',$slug)->first();
// would use app/posts/show.blade.php
return View::make('posts.show')->with(array(
'post' => $post,
));
}
Then you can route it like this:
Route::get('post/{slug}', 'PostsController@showBySlug')
->where('slug', '[\-_A-Za-z]+');`
...which has the added bonus of allowing you an easy way to link straight to the slug routes on an index page, for example:
@foreach ($posts as $post)
<h2>{{ HTML::link(
action('PostsController@showBySlug', array($post->slug)),
$post->title
)}}</h2>
@endforeach
Also in PHP:
- Hie date format php
- You are *required* to use the date.timezone setting or t
- error text encode php json
- check if in array key php
- check data type php
- drupal 8 twig filters
- current datae in php
- add days in current date php
- check chartercount in php
- a non well formed numeric value encountered
- php remove spaces from string
- db seeder artisan
- command to install php5.4 in ubuntu 18.04
- create laravel 5.8 project using composer
- does php use integer divison
- binary base64 decode php
- explain email injection
- add 1 month to date php
- array get only the value without duplicate
- Get the content of a specific page (by ID)
- artisan migrate
- date time stamp php
- $this- attribute laravel
- array key is true