جشنواره بهارانه راکت! ۳۵% تخفیف ویژه بر روی دوره‌های آموزشی

مشاهده دوره‌ها
ثانیه
دقیقه
ساعت
روز
رایموند
1 سال پیش توسط رایموند مطرح شد
1 پاسخ

مشکل ثبت داده ها در لایو وایر

درود دوستان..
من لایو وایر فرمی ساختم که داده دریافت و در پایگاه داده ثبت بشه...
اما مشکل اینجاست که هیچ داده ای ثبت نمی کند.

کدهای زیر:

User.php

protected $fillable = [
        'name',
        'username',
        'is_admin',
        'birthday',
        'active_sms',
        'email_connection',
        'mobile_connection',
        'email',
        'group_id',
        'mobile',
        'phone',
        'sing_id',
        'verified',
        'gender',
        'role_id',
        'push_id',
        'task_start',
        'task_review',
        'task_complate',
        'manage_start',
        'manage_review',
        'manage_complate',
        'manage_end',
        'manage_cancel',
        'pic',
        'position',
        'password',
    ];

Add.php

use WithFileUploads;

    public User $user;
    public $pic;
    public $sign;

    public function mount()
    {
        $this->user = new User();
    }

    public function render()
    {
        return view('livewire.support.users.add');
    }

    protected $rules = [
        'name' => 'nullable',
        'username' => 'nullable',
        'email' => 'nullable',
        'password2' => 'nullable',
        'is_admin' => 'nullable',
        'birthday' => 'nullable',
        'active_sms' => 'nullable',
        'email_connection' => 'nullable',
        'mobile_connection' => 'nullable',
        'group_id' => 'nullable',
        'mobile' => 'nullable',
        'sing_id' => 'nullable',
        'gender' => 'nullable',
        'role_id' => 'nullable',
        'position' => 'nullable',
        'pic' => 'nullable',
        'task_start' => 'nullable',
        'task_review' => 'nullable',
        'task_complete' => 'nullable',
        'manage_start' => 'nullable',
        'manage_review' => 'nullable',
        'manage_complete' => 'nullable',
        'manage_end' => 'nullable',
        'manage_cancel' => 'nullable',

    ];
    public function updated($name)
    {
        $this->validateOnly($name);
    }

    public function userForm()
    {
        $this->validate();
        $user = User::query()->create([
            'name' => $this->user->name,
            'lname' => $this->user->lname,
            'username' => $this->user->username,
            'email' => $this->user->email,
            'group_id' => $this->user->group_id,
            'mobile' => $this->user->mobile,
            'phone' => $this->user->phone,
            'gender' => $this->user->gender,
            'role_id' => $this->user->role_id,
            'position' => $this->user->position,
            'is_admin' => 0,
            'task_start' => $this->user->task_start,
            'task_review' => $this->user->task_review,
            'task_complete' => $this->user->task_complete,
            'manage_start' => $this->user->manage_start,
            'manage_review' => $this->user->manage_review,
            'manage_complete' => $this->user->manage_complete,
            'manage_end' => $this->user->manage_end,
            'manage_cancel' => $this->user->manage_cancel,
            'email_connection' => $this->user->email_connection,
            'mobile_connection' => $this->user->mobile_connection,
            'password' => Hash::make($this->user->password2),

        ]);
        if ($this->user->active_sms == true) {
            $user->update([
                'active_sms'=>1
            ]);
        }
        if ($this->pic) {
            $user->update([
                'pic' => $this->uploadImage()
            ]);
        }
        if ($this->sign) {
            $user->update([
                'sing_id' =>$this->uploadImage2()
            ]);
        }
        return $this->redirect(route('users.index'));
    }
    public function uploadImage()
    {
        $year = now()->year; $month = now()->month; $directory = "users/$year/$month";
        $name= $this->pic->getClientOriginalName(); $this->pic->storeAs($directory,$name);
        return "$directory/$name";
    }
    public function uploadImage2()
    {
        $year = now()->year; $month = now()->month; $directory = "sign/$year/$month";
        $name= $this->sign->getClientOriginalName(); $this->sign->storeAs($directory,$name);
        return "$directory/$name";
    }

Add.blade.php

<div class="p-5">
        <div class="col-md-6 offset-3">
            <div class="card">
                <div class="card-header">
                    افزودن کاربر جدید
                </div>
                <div class="card-body">
                    <form enctype="multipart/form-data" wire:submit.prevent="userForm">
                        <div class="row g-3">
                            <div class="col-6 mb-3">
                                <label for="input1" class="form-label">نام و نام خانوادگی</label>
                                <input type="text" class="form-control" id="input1" wire:model.defer="name">
                            </div>
                            <div class="col-6 mb-3">
                                <label for="input2" class="form-label">نام کاربری</label>
                                <input type="text" class="form-control" id="input2" wire:model.defer="username">
                            </div>
                            <div class="col-6 mb-3">
                                <label for="input3" class="form-label">ایمیل</label>
                                <input type="email" class="form-control" id="input3" wire:model.defer="email">
                            </div>
                            <div class="col-6 mb-3">
                                <label for="input4" class="form-label">شماره موبایل</label>
                                <input type="text" class="form-control" id="input4" wire:model.defer="mobile">
                            </div>
                            <div class="col-6 mb-3">
                                <label for="input5" class="form-label">سمت کاربری</label>
                                <input type="text" class="form-control" id="input5" wire:model.defer="position">
                            </div>
                            <div class="col-6 mb-3">
                                <label for="input6" class="form-label">رمز عبور</label>
                                <input type="password" class="form-control" id="input6" wire:model.defer="password2">
                            </div>

                            <div class="col-4 mb-3">
                                <label>گروه سازمانی</label>
                                <select class="form-select" wire:model.defer="group_id" aria-label="Default select example">
                                    <option selected>انتخاب کنید ...</option>
                                    <option value="1">مدیران اصلی</option>
                                    <option value="2">مدیران</option>
                                    <option value="3">برنامه نویس</option>
                                    <option value="4">بخش اداری</option>
                                    <option value="5">بخش فروش</option>
                                    <option value="6">بخش پشتیبانی</option>
                                </select>
                            </div>
                            <div class="col-4 mb-3">
                                <label>نقش کاربری</label>
                                <select class="form-select" wire:model.defer="role_id" aria-label="Default select example">
                                    <option selected>انتخاب کنید ...</option>
                                    <option value="1">مدیر سایت</option>
                                    <option value="2">پشتیبان سایت</option>
                                    <option value="3">کارشناس فروش</option>
                                    <option value="4">کارشناس مالی</option>
                                    <option value="5">کارشناس پشتیبانی</option>
                                    <option value="6">مدیر بخش فروش</option>
                                </select>
                            </div>
                            <div class="col-4 mb-3">
                                <label>جنسیت</label>
                                <select class="form-select" wire:model.defer="gender" aria-label="Default select example">
                                    <option selected>انتخاب کنید ...</option>
                                    <option value="1">آقا</option>
                                    <option value="2">خانم</option>
                                </select>
                            </div>
                        </div>

                        <label class="me-5">ارتباط کاربر</label>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="email_connection" id="inlineCheckbox1" value="1">
                            <label class="form-check-label" for="inlineCheckbox1">ایمیل</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="mobile_connection" id="inlineCheckbox2" value="2">
                            <label class="form-check-label" for="inlineCheckbox2">موبایل</label>
                        </div>
                        <div class="form-check form-check-inline form-switch">
                            <input class="form-check-input" type="checkbox" role="switch" wire:model.defer="active_sms" id="flexSwitchCheckDefault">
                            <label class="form-check-label" for="flexSwitchCheckDefault">پیامک</label>
                        </div>
                        <br class="mb-3">
                        <label class="me-5">اختیارات نامه ها</label>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="task_start" id="inlineCheckbox1" value="1">
                            <label class="form-check-label" for="inlineCheckbox1">شروع</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="task_review" id="inlineCheckbox2" value="2">
                            <label class="form-check-label" for="inlineCheckbox2">بررسی</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="task_complate" id="inlineCheckbox3" value="3">
                            <label class="form-check-label" for="inlineCheckbox3">بایگانی</label>
                        </div>

                        <br class="mb-4">
                        <label class="me-5">اختیارات وظایف ها</label>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="manage_start" id="inlineCheckbox1" value="1">
                            <label class="form-check-label" for="inlineCheckbox1">شروع وظیفه</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="manage_review" id="inlineCheckbox2" value="2">
                            <label class="form-check-label" for="inlineCheckbox2">بررسی اولیه وظیفه</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="manage_complate" id="inlineCheckbox3" value="3">
                            <label class="form-check-label" for="inlineCheckbox3">تکمیل وظیفه</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="manage_end" id="inlineCheckbox4" value="4">
                            <label class="form-check-label" for="inlineCheckbox4">خاتمه وظیفه</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="checkbox" wire:model.defer="manage_cancel" id="inlineCheckbox5" value="5">
                            <label class="form-check-label" for="inlineCheckbox5">رد شده</label>
                        </div>

                        <div class="row m-4">
                            <div class="col-md-6">
                                <label>عکس کاربر</label>
                                <div class="input-group mb-3">
                                    <input type="file" class="form-control" wire:model.defer="pic" id="inputGroupFile01">
                                    <label class="input-group-text" for="inputGroupFile01">ارسال</label>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <label>امضای کاربر</label>
                                <div class="input-group mb-3">
                                    <input type="file" class="form-control" wire:model.defer="sing_id" id="inputGroupFile02">
                                    <label class="input-group-text" for="inputGroupFile02">ارسال</label>
                                </div>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary">ثبت کاربر جدید</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

web.php

Route::get('/users/add', \App\Http\Livewire\Support\Users\Add::class)->name('users.add');

در نتیجه وقتی اطلاعات وارد می کنید و دکمه ثبت رو کلیک می کنید هیچ واکنشی نشون نمیده به اصصلاح داده ای ثبت نمی کند و انتهای پیوند علامت سوال میاد.

http://127.0.0.1:8000/users/add?

کجای کد ایراد دارد که رفع کنم...


ثبت پرسش جدید
رایموند
تخصص : مختصص وردپرس - برنامه نویس لار...
@Raymond 1 سال پیش مطرح شد
1

در قسمت رندر برای بارگذاری صفحات کد زیر را ضاافه کردم و اوکی شد:

public function render()
    {
        return view('livewire.support.users.create')
            ->extends('layouts.app')
            ->section('content');
    }

وقتی که لایووایر در پروژه استفاده می کنید و در صفحاتی که در blade کد زیر به کار بگیرید, لایووایر کار نخواهد کرد.

@extends('layouts.app')
@section('content')

@endsection

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام