Route::middleware('web')
->namespace('App\\Http\\Controllers')
->group(base_path('routes/web.php'));
$validatedData = $request->validate([
// ... ваши правила валидации ...
]);
$object = MyObject::create($validatedData);
id | text
id | content | …
tag_id | content_id
class Content extends Model {
public function tags(): BelongsToMany {
return $this->belongsToMany(Tag::class);
}
}
class Tag extends Model {
public function contents(): BelongsToMany {
return $this->belongsToMany(Content::class);
}
}
dd($content->tags);
Route::post("article/{article}", [ArticleController::class, 'update')
->name('article.update');
class ArticleController extends Controller
{
public function update(Article $article, ArticleUpdateRequest $request)
{
$article
->fill($request->validated())
->save();
return redirect(route('article.edit', $article));
}
}
Route::name('user.')->group(function(){
//Route::view('/private','priv')->middleware(('auth'))->name('private');
Route::view('/private','priv')->middleware(['auth'])->name('private');
Route::get('/login',function(){
if(Auth::check()){
return redirect(route('user.private'));
}
return view('loggin'); // Вынести из условия
})->name('login');
Route::get('/reg',function(){
if(Auth::check()){
return redirect(route('user.private'));
}
return view('reg'); // Вынести из условия
})->name('reg');
});
use Illuminate\Database\Eloquent\Factories\Sequence;
public function run()
{
$list = ['secret1','secret2','secret3']; //получаем список данных;
shuffle($list); // Перемешиваем
Order::factory(20)
->state(new Sequence(function () use (&$list) {
return ['secret_id' => array_pop($list)];
}))
->create();
}
Route::middleware('admin')
->prefix('admin')
->name('admin.')
// ->namespace($this->namespace)
->group(base_path('routes/admin.php'));
Route::get('auth', 'AuthController@show')->name('auth');
<option value="{{ $category->id }}">{{ $category->name }}</option>
поэтому использую ajax. Как я понял, в контроллере нельзя получить сведения о пользователе, если данные передаются таким споссобом
/api/blabla
/api
по умолчанию предлагается использовать для stateless запросов./ajax/bla
, тогда все запросы будут проходить через группу миддлвэров web и стартовать сессию.Route::prefix('api')
// ->middleware('api')
->middleware('web')
->group(base_path('routes/api.php'));
Auth::user()
будет содержать текущего пользователя.npm run build
npm run dev
<script type="module" src="http://[::1]:5173/@vite/client"></script>
<link rel="stylesheet" href="http://[::1]:5173/resources/assets/css/app.scss" />
…
<div id="table">
@include('table')
</div>
…
<table>
<tr>
...
</tr>
@foreach ($data as $element)
<tr>
<td>{{ $element['date'] }}</td>
...
</tr>
@endforeach
</table>
Route::get('getTable', function(){
...
return response()->json([
'target' => 'table',
'html' => view('table', [...])->render()
])
});
function getChank(url, data) {
return fetch(url, {
body: data,
}).then(response => response.json())
.then(response => {
const target = document.getElementById(response.target);
target.innerHTML = response.html;
});
}
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@hasSection('title')
<title>@yield('title') :: {{ config('app.name') }}</title>
@else
<title>{{ config('app.name') }}</title>
@endif
@vite(['resources/sass/app.scss'])
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
<body>
@yield('body')
@vite(['resources/js/app.js'])
@stack('scripts')
</body>
</html>
@extends('layouts.base')
@section('body')
<div>
@yield('content')
</div>
@endsection
@extends('layouts.base')
@section('body')
<div>
<header>
@include('partials.app.header')
</header>
<main>
@yield('content')
</main>
</div>
@endsection
@extends('layouts.auth')
@section('content')
<form> </form>
@endsection
@extends('layouts.app')
@section('content')
Главная
@endsection
"scripts": {
"build:site": "vite build --config site.vite.config.js",
"build:admin": "vite build --config admin.vite.config.js",
}
~/
----/site.com
----/public_html
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->usePublicPath(base_path('public_html'));
}
}
public function productPage(Category $category, Product $product){
// $currentProduct = Product::find($product); это уже не нужно
// В переменной $product уже будет объект
return view('product', compact('product'));
}