I have the following route in laravel.
Route::get('/{id}', 'HomeController@profile')->where('id', '[0-9A-Za-z\-]+');
If id
corresponds to id in a database, ex: site.com/23
then I am able to fetch results from database with that specific id. However, if I want to fetch something like a title slug ex: site.com/this-is-title
then it won't work at all. I have no idea how to tell laravel to query based on anything other than an database id
.
My controller is:
class HomeController extends BaseController{
public function profile($company_slug){
$result = Clients::all($company_slug);
return View::make("home.profiles", compact("result"));
}
}
Here is my template.
@extends("layouts.master")
@section("main-content")
<?php
{{ $result->company_slug }}
?>
@stop
There is no output. If I do <?php var_dump($result) ?>
I get NULL
.
But as I said, if I pass an id site.com/32
then I get result from database a for that id.