Русское сообщество разработки на PHP-фреймворке Laravel.
Ты не вошёл. Вход тут.
создал тестовый сайт на laravel 5,4 по умолчанию laravel работает с адресами вида https://test.ru/category/news
и https://test.ru/show/privet-mir.
Я убрал из Адресов сигменты category и show.
В Базе поля называются Articles_alias и categories_alias
Файл web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::group(['as' => 'admin.', 'prefix' => 'admin', 'namespace' => 'Admin'], function(){
Route::resource('/', 'DashbordController');
Route::resource('/categories', 'CategoryController');
});
Route::get('/id{id}', 'HomeController@index')->name('home');
Route::get('/{articles_alias}','MainController@show')->name('show');
Route::get('/{categories_alias}', 'MainController@Categories')->name('categories');
Route::get('/', 'MainController@index')->name('main');
Auth::routes();
файл MainController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Article;
use App\Category;
use MetaTag;
use App\Home;
class MainController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$articles = Article::all();
$meta = Home::find(1);
MetaTag::set('title', $meta->title);
MetaTag::set('description', $meta->description);
MetaTag::set('keywords', $meta->keywords);
return view('welcome', compact('articles'));
}
public function categories($categories_alias){
$category = Category::where('categories_alias', $categories_alias)->find();
$articles = $category->Articles()->paginate(10);
return View('categories', compact('category', 'articles'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($articles_alias)
{
$post = Article::where('articles_alias', $articles_alias)->firstOrFail();
MetaTag::set('title', $post->title);
return View('show', compact('post', 'name'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
скрин ошибки
Изменено nikson (13.04.2019 11:23:53)
Не в сети