middleware
routes/web.php```
Route::group([‘prefix’ => ‘member’, ‘as’ => ‘member.’, ‘middleware’ => [‘auth’, ‘setLocale:zh-tw’]], function () {
Route::get('/', App\Http\Livewire\MemberList::class);
});
app/Http/Middleware/SetLocale.php.php``` namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; class SetLocale { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, string $lang) { app()->setLocale($lang); return $next($request); } }
https://github.com/livewire/livewire/issues/1908
https://laravel-news.com/livewire-file-upload
Real-Time File Validation```
use Livewire\Component;
use Livewire\WithFileUploads;
class Show extends Component
{
use WithFileUploads;
public $files = []; public function updatedFiles() // 即時檢查檔案格式 { $this->validate([ 'files.*' => 'image|max:1024', // 1MB Max ]); } public function store() { $filenames = collect($this->photos)->map->store('photos'); 'files' => $filenames->implode(','), updatedFiles() is Hook into the “updated”
updatedPhoto public $Photo
updatedPhotos public $photos = []
updatedFile public $file
updatedFiles public $files = []
Use - and lowwercase App/Http/Livewire/Order/DropdownMaterial.php```
class DropdownMaterial extends Component
{
resources/views/livewire/order/create.blade.php``` @livewire('order.dropdown-material', ['post' => $order_material_id])
When juse livewire at blade.php
Must have Div At first. <div style="text-align: center"> <button wire:click="increment">+</button> <h1>{{ $count }}</h1> </div> +{{ $count }}
App/Http/Livewire/Orders.php```
namespace App\Http\Livewire;
use Gate;
use Livewire\Component;
use Symfony\Component\HttpFoundation\Response;
class Orders extends Component
{
public function render()
{
abort_if(Gate::denies(‘order_access’), Response::HTTP_FORBIDDEN, ‘403 Forbidden’);
return view('livewire.order'); } }
resources/views/livewire/order.blade.php
@extends(‘layouts.app’)
@section(‘content’)
@livewire(‘order.show’)
@endsection
App/Http/Livewire/Order/Show.php namespace App\Http\Livewire\Order;
public function render() { abort_if(Gate::denies('order_access'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $this->orders = Order::all(); // Order::where('owner_id', auth()->id())->get(); // 只能看自己 return view('livewire.order.show'); } resources/views/livewire/order/show.blade.php
{{ virables }}