I am trying to fetch list of tags, but i keep getting this error :
NotFoundHttpException in Handler.php line 131:
No query results for model [App\Tag]
Here is my routes file
<?php
Route::get('/', function () {
return view('home');
});
Route::get('/dashboard', function () {
return view('dashboard');
});
Route::get('/browse', 'TeamsController@index');
Route::get('/teams/create', 'TeamsController@create');
Route::post('/teams/create', 'TeamsController@store')->name('browse');
Route::get('/teams/tags/{tag}', 'TagsController@index')->name('tagsIndex');
Auth::routes();
Route::get('/home', 'HomeController@index');
My Tag model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Team;
class Tag extends Model
{
public function teams()
{
return $this->belongsToMany(Team::class);
}
public function getRouteKeyName()
{
return 'name';
}
}
My TagsController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Tag;
class TagsController extends Controller
{
public function index(Tag $tag)
{
$tags = $tag->load('teams');
return view('team.index', compact('tags'));
}
}
Why it happens? Whats is the solution of this problem?
Any help would be great!