- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用 laravel livewire 做一个 SPA,我想使用 wire:click 来触发组件中的一个功能,但它不起作用,如果代码困惑这是我第一次在这里发布并且我不确定要发布什么,请原谅这是我的代码来解决这些问题谢谢
主 Blade .php
@section('content')
<div>
<div class="row justify-content-center">
<div class="col-12">
<div class="card my-3">
<!-- header -->
<div class="card-header d-inline-flex">
<h3 class='mr-2'>Categories</h3>
<div>
<a href="javascript:void(0);" wire:click='createCategory' class="btn btn-success ">Add NewCategory</a>
</div>
</div><!-- header -->
<div class="card-body">
<!-- alerts -->
@include('admin.includes.alerts.errors')
@include('admin.includes.alerts.success')
<!-- alerts -->
<!-- if True , create form will show , if not will stay disabled -->
@if ($showCreateForm)
@livewire('admin.category.create' )
@endif
<!-- if True , create form will show , if not will stay disabled -->
<!-- Table -->
<div class="table-responsive">
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Image</th>
<th>Name</th>
<th>Slug</th>
<th>Status</th>
<th>Parent</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($categories as $category)
<tr>
<td>{{$category->id}}</td>
{{-- <td>{{storage_path(app\livewire-tmp\$category->image)}}" /></td> --}}
<td>{{$category->name}}</td>
<td>{{$category->slug}}</td>
<td class=" {{$category->isActive()==='Active'? 'text-success':'text-danger'}}">
{{$category->isActive()}}</td>
<td>{{ !empty($category->parent) ? $category->parent->name:'' }}</td>
<td>
<a href="" class="btn btn-warning">Edit</a>
<a href="" class="btn btn-danger">Delete</a>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Image</th>
<th>Name</th>
<th>Slug</th>
<th>Status</th>
<th>Parent</th>
<th>Action</th>
</tr>
</tfoot>
</table>
<div>
{!!$categories->links()!!}
</div>
</div>
<!-- Table -->
</div><!-- body -->
</div>
</div>
</div>
</div>
@endsection
和组件 Main.php ,
<?php
namespace App\Http\Livewire\Admin\Category;
use App\Models\Admin\Category;
use Livewire\Component;
use Livewire\WithPagination;
class Main extends Component
{
use WithPagination;
protected $categories;
public $showCreateForm = false;
public $showEditForm = false;
public function render()
{
$categories = Category::orderBy('id','desc')->paginate(12);
return view('livewire.admin.category.main',[
'categories' => $categories,
]) ->layout('layouts.admin');
}
public function createCategory()
{
$this->showCreateForm = !$this->showCreateForm;
}
public function update_Category($id)
{
$categories = Category::whereId($id);
if ($categories) {
$this->emit('getCategoryid' , $categories);
$this->showEditForm = !$this->showEditForm;
$this->showCreateForm = false;
}
}
public function delete_Category($id)
{
$this->showCreateForm = !$this->showCreateForm;
}
}
<div>
<form role="form" wire:submit.prevent="create" method="POST" enctype="multipart/form-data">
@csrf
<div class="card-body">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="exampleInputEmail1">Parent</label>
<select type="select" class="form-control" id="exampleInputEmail1" wire:model="parent_id" name="parent_id">
<option selected value> -- select an option -- </option>
{{-- @if (is_array($categories) || is_object($categories) || !empty($categories)) --}} @foreach ($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach {{-- @endif --}}
</select>
</div>
</div>
<!-- 1 -->
<div class="col-6">
<div class="form-group">
<label for="exampleInputPassword1">Category Name</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Name" wire:model="name" name="name"> @error('name') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- 2 -->
<div class="col-6">
<div class="form-group">
<label for="exampleInputPassword1">Slug Name</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Name" wire:model="slug" name="slug"> @error('slug') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- 3 -->
<div class="col-6">
<div class="form-group">
<label for="exampleFormControlFile1">Image</label>
<input type="file" wire:model="image" class="form-control-file" id="exampleFormControlFile1" name="image"> @error('image') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- 4 -->
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1" wire:model="is_active" name="is_active">
<label class="form-check-label" for="exampleCheck1">is Active</label> @error('is_active') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<?php
namespace App\Http\Livewire\Admin\Category;
use Livewire\Component;
use App\Models\Admin\Category;
use Livewire\WithFileUploads;
use Illuminate\Support\Str;
use Livewire\WithPagination;
use Intervention\Image\Facades\Image;
class Create extends Component
{
use WithFileUploads;
use WithPagination;
public $slug , $name , $image , $parent_id , $is_active;
protected $rules = [
'slug' => 'required|unique:categories,slug',
'name' => 'required',
'image'=> 'nullable|image|max:1024'
];
protected $categories;
public function render()
{
$categories = Category::orderBy('id','desc')->paginate(12);
return view('livewire.admin.category.create' , [
'categories' => $categories,
]);
}
public function create()
{
$this->validate();
$data = [
'name' => $this->name,
'slug' => $this->slug,
'is_active'=> $this->is_active,
'image'=> $this->image,
'parent_id'=> $this->parent_id,
];
//image upload
try {
if ($image = $this->image) {
$filename = Str::slug($this->name).'.'.$image->getClientOriginalExtension();
$path = public_path('assets/image/'.$filename);
Image::make($image->getRealPath())->save($path,100);
}
Category::create($data);
$this->reset();
return $this->addError('success' , 'Created Successfuly');
} catch (\Throwable $th) {
return $this->addError('error', 'Something Wrong Happens');
}
}
}
<div>
<form role="form" method="POST" enctype="multipart/form-data" wire:submit.prevent="update">
@csrf
<div class="card-body">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="exampleInputEmail1">Parent</label>
<select type="select" class="form-control" id="exampleInputEmail1" wire:model="parent_id" name="parent_id">
<option></option>
{{-- @if (is_array($categories) || is_object($categories) || !empty($categories)) --}} @foreach ($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach {{-- @endif --}}
</select>
</div>
</div>
<!-- 1 -->
<div class="col-6">
<div class="form-group">
<label for="exampleInputPassword1">Category Name</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Name" wire:model="name" value='{{$category->name}}' name="name"> @error('name') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- 2 -->
<div class="col-6">
<div class="form-group">
<label for="exampleInputPassword1">Slug Name</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Name" wire:model="slug" name="slug" value='{{$category->slug}}'> @error('slug') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- 3 -->
<div class="col-6">
<div class="form-group">
<label for="exampleFormControlFile1">Image</label>
<input type="file" class="form-control-file" id="exampleFormControlFile1" name="image">
<img value='{{$category->image}}' alt="" srcset=""> @error('image') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- 4 -->
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1" wire:model="is_active" name="is_active">
<label class="form-check-label" for="exampleCheck1">is Active</label> @error('is_active') <span class="error text-danger">{{ $message }}</span> @enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<?php
namespace App\Http\Livewire\Admin\Category;
use Livewire\Component;
use App\Models\Admin\Category;
class Edit extends Component
{
protected $categories , $cat_id;
public $slug , $name , $image , $old_image , $parent_id , $is_active;
protected $listeners = ['getCategoryid'=>'getID'];
public function mount()
{
$this->categories = Category::whereId($this->cat_id)->first();
}//mout
public function render()
{
$categories = Category::all();
return view('livewire.admin.category.edit' , [
'categories' => $categories,
]);
}//render
public function update($id)
{
}//update
public function getID($categories)
{
$this->categories = $categories;
// Data
$this->slug = $this->$categories['slug'];
$this->name = $this->$categories['name'];
$this->image = $this->$categories['image'];
$this->old_image = $this->$categories['old_image'];
$this->parent_id = $this->$categories['parent_id'];
$this->is_active = $this->$categories['is_active'];
}//getID
}
最佳答案
所有 HTML 代码都应该用单个 <div>.
覆盖然后它将起作用。
关于javascript - laravel Livewire 电线 :click not firing the function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64089344/
我正在学习如何使用 livewire 和 laravel,我试图通过输入绑定(bind)一些数据 我写了这段代码: home.blade.php: Home @livewireSt
我有一个包含几张卡片的 livewire 概览组件。在这些卡片中有一个 livewire 表单,但是当我将表单包含到概览组件中时,我的整个 livewire 停止工作。 我添加到概览组件文件中的唯一一
如 docs 中所述,您可以在自定义路径中创建组件,这与默认的 views/livewire/ 和 Http/Livewire 不同。为了更好地组织,我创建了子文件夹: $ php artisan m
如 docs 中所述,您可以在自定义路径中创建组件,这与默认的 views/livewire/ 和 Http/Livewire 不同。为了更好地组织,我创建了子文件夹: $ php artisan m
我正在尝试将用户的地理坐标(纬度和经度)发送到 livewire 组件以加载附近的地点。但是我无法发送它,因为它们是 javascript 变量。问题是如何将 javascript 变量发送到 liv
我想做的是从数据库中获取一些数据并将其显示在 Input Value 字段中,但这里的问题是当我使用 wire:model='some_input_name' 值不显示。如果我删除 wire:mode
在我应用新的 livewire V2 编程风格之前,我有一个连接到模型的各个属性的表单。为了触发字段的实时验证,我在组件中使用了这个(例如 name 属性): public function upda
有 3 个 livewire 组件 UserIsExpired、UserIsActive 和 UserIsPending 以及每个组件对应的 3 个按钮。单击按钮时,它应该用其各自的组件替换先前的组件
有 3 个 livewire 组件 UserIsExpired、UserIsActive 和 UserIsPending 以及每个组件对应的 3 个按钮。单击按钮时,它应该用其各自的组件替换先前的组件
I have used Laravel 10 with Livewire 3 and Turbolink.我已经使用Laravel 10与Livewire 3和Turbolink。 When
我有一个带有“存储”方法的 Laravel Controller 。即存储(请求 $request)。 对于 View ,我想嵌入一个 livewire 组件,然后利用 livewire 组件方法中现
在 laravel 7/livewire 1.3/alpinejs 2 项目中,我制作了 crud,当为了添加/编辑,我将 livewire.admin.app-news.form 包含在数据列表中(
我使用的是 laravel 8。 我在 RouteServiceProvider 中定义了 protected 命名空间: protected $namespace = 'App\Http\Contr
我正在使用 Laravel Livewire,这里我有 3 个表格显示在一页上,但问题是分页显示正确但不起作用(URL 更改为 http://127.0.0.1:8000/blogpost?EnPos
我想在更新父组件时刷新子组件,并且只有该组件的子组件应该更新,因为我想在页面的其他地方重用子组件。组件结构如下。UserShow.php class UserShow extends Componen
我可以将数据传递给组件,但在 Alpine js 的模态中,数据为空。 这是类: public $code, $products; public function getData($id)
我有2个livewire组件,第一个仅显示购物车的session变量,第二个只是在购物车中添加项目(一种非常原始的形式,带有sku,标题,价格和数量)。 这两个组件本身都可以正常工作。但是,当我从
我尝试通过 laravel 队列加载多个图像,如下所示: Controller : foreach ($this->imagenes as $pathGaleria) { $image
我想了解 Livewire 组件中的挂载和渲染方法有什么区别,因为我看到过这两种方法都用于定义变量初始状态的示例。例如,当您使用模型中的记录实例化一个变量时,“哪个位置是使用 ORM 语法加载数据的正
我尝试通过 laravel 队列加载多个图像,如下所示: Controller : foreach ($this->imagenes as $pathGaleria) { $image
我是一名优秀的程序员,十分优秀!