mDelshad

Member Since 2 Years Ago

Experience Points
5,480
Total
Experience

4,520 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 2
5,480 XP
May
04
6 days ago
Activity icon

Started a new Conversation Can't Update Array Data In Laravel

In the table, the information field is an array, and when I try to edit the information inside this array, I get this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'nationalCode' in 'where clause' (SQL: select * from `kycs` where ((`nationalCode` = 1234567891 and `state` = tehran and `city` = tehran and `address` = example address and `zipcode` = 9477143812)) limit 1)

this is my code :

        if ($kyc = auth()->user()->kyc()->where('user_id', Auth::User()->id)->first()) {
            //   $data = Kyc::where('user_id', Auth::user()->id)->first();
            if ($kyc->selfie['status'] == 'rejected') {
                $this->validate(
                    [
                        'nationalCode' => 'required|nationalcode',
                        'state' => 'required',
                        'city' => 'required',
                        'address' => 'required',
                        'zipcode' => 'required|zipcode',
                        'selfie' => 'required|mimes:jpg,jpeg,png|max:2024',
                    ]
                );
                $selfie_url = $this->selfie->store('documents/'.Crypt::decryptString($kyc->secret));
                Kyc::updateOrCreate([
                    [
                        'information' => [
                            'nationalCode' => $this->nationalCode,
                            'state' => $this->state,
                            'city' => $this->city,
                            'address' => $this->address,
                            'zipcode' => $this->zipcode,
                        ],
                        'selfie' => [
                            'url' => Crypt::encryptString($selfie_url),
                            'status' => 'pending',
                            'last_update' => Carbon::now(),
                            'desc' => '',
                        ],
                    ],
                ]);

                return redirect()->route('frontend.auth.verification.notice');
            }

and migration :

        Schema::create('kycs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->string('secret')->unique();
            $table->json('information');
            $table->json('selfie');
            $table->timestamps();
        });
        Schema::table('kycs', function ($table) {
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }
May
02
1 week ago
Activity icon

Started a new Conversation Use Two Form In Livewire

i have a two form in livewire but one of the forms not work !

form 1 :

                <form wire:submit.prevent="sendCodeMobile">
                    <div class="form-control-wrap">
                        <div class="form-icon form-icon-right">
                            <em class="icon ni ni-mobile"></em>
                        </div>
                        <input type="number"  wire:model="mobileNumber" id="mobileNumber" name="mobileNumber" class="form-control" style="text-align: center;" placeholder="لطفا شماره موبایل خود را وارد نمایید">
                    </div>
                    @error('mobileNumber')
                    <span class="badge badge-dot badge-danger" style="margin-top: 12px;margin-bottom: 12px;">{{ $message }}</span>
                    @enderror
                    <br>
                    <div class="row g-4">
                        <div class="btn-group">
                            <button type="submit" class="btn btn-dim btn-outline-primary">ثبت شماره موبایل</button>
                        </div>
                    </div>
                    <br>
                </form>

form 2 (not work) :

                    <form wire:submit.prevent="verifyMobile">
                    <div class="nk-modal-text">
                        <input type="number" wire:model="code" class="form-control"  style="text-align: center;" placeholder="کد تایید ۵ رقمی ارسال شده به تلفن همراه خود را وارد نمایید.">
                    </div>
                    <div class="nk-modal-action">
                        <button type="submit" class="btn btn-lg btn-mw btn-primary" >تایید</button>
                    </div>
                    </form>
Apr
02
1 month ago
Activity icon

Started a new Conversation Parsing Data To Javascript With Laravel Controller

i send data with this code to js :

$user = User::where('id' , $this->selectedItem)->first();
   
      $this->dispatchBrowserEvent('userModal', [
        'name' => $user->name,
        'signup' => jdate($user->created_at),
      ]);

jDate() Is a function to convert to Persian date...

but in frontend for signup i will receive a empty value and this is js code for recieve data :

     window.addEventListener('userModal', event => {
            console.log(event.detail);
    });
Apr
01
1 month ago
Activity icon

Replied to Problem With Datatable In Laravel

i added code to question.. Please check to see which part I made a mistake

Activity icon

Replied to Problem With Datatable In Laravel

not worked !

Mar
30
1 month ago
Activity icon

Started a new Conversation Problem With Datatable In Laravel

In Laravel I use the datatable plugin for my tables. For the users view section, because I wanted the administrator to be able to see brief information about that user by clicking on a button on the same page. I used livewire, which by clicking on that button opens a modal with information from that user. But there is a problem, after the modal is opened, the table as a whole becomes a simple table like search or pagination Ever had this problem? Do you have a solution for it?

this is livewire view:

<div>
    <table class="datatable-init nk-tb-list nk-tb-ulist" id="jadval" name="jadval">
        <thead>
            <tr class="nk-tb-item nk-tb-head">
                <th class="nk-tb-col">
                    <span class="sub-text">نام کاربر</span>
                </th>
                <th class="nk-tb-col tb-col-mb">
                    <span class="sub-text">موجودی</span>
                </th>
                <th class="nk-tb-col tb-col-md">
                    <span class="sub-text">تلفن</span>
                </th>
                <th class="nk-tb-col tb-col-lg">
                    <span class="sub-text">وضعیت حساب</span>
                </th>
                <th class="nk-tb-col tb-col-lg">
                    <span class="sub-text">آخرین ورود</span>
                </th>
                <th class="nk-tb-col tb-col-md">
                    <span class="sub-text">وضعیت</span>
                </th>
                <th class="nk-tb-col nk-tb-col-tools text-right"></th>
            </tr>
        </thead>
        <tbody>
            @foreach ($Users as $user)
            <tr class="nk-tb-item" wire:key="{{$user->id}}" wire:ignore>
                <td class="nk-tb-col">
                    <div class="user-card">
                        <div class="user-info">
                            <span class="tb-lead">{{$user->name}}
                                <span class="dot dot-success d-md-none ml-1"></span>
                            </span>
                            <span>{{$user->email}}</span>
                        </div>
                    </div>
                </td>
                <td class="nk-tb-col tb-col-mb">
                    <span class="tb-amount">{{ number_format($user->balance)}}
                        <span class="currency">تومان</span>
                    </span>
                </td>
                <td class="nk-tb-col tb-col-md">
                    <span>{{$user->mobile}}</span>
                </td>
                <td class="nk-tb-col tb-col-lg" data-order="Email Verified - Kyc Unverified">
                    <ul class="list-status">
                        <li>
                            @if ($user->isVerified())
                            <em class="icon text-success ni ni-check-circle"></em>
                            <span>ایمیل</span>
                            @else
                            <em class="icon ni ni-alert-circle"></em>
                            <span>ایمیل</span>
                            @endif
                        </li>
                        <li>

                            @if ($user->fullActive())
                            <em class="icon text-success ni ni-check-circle"></em>
                            <span> احراز هویت </span>
                            @else
                            <em class="icon ni ni-alert-circle"></em>
                            <span>عدم احراز هویت</span>
                            @endif

                        </li>
                    </ul>
                </td>
                <td class="nk-tb-col tb-col-lg">
                    <span>{{jdate($user->last_login_at)}}</span>
                </td>
                <td class="nk-tb-col tb-col-md">
                    @if ($user->isActive())
                    <span class="tb-status text-success">فعال</span>
                    @else
                    <span class="tb-status text-danger">غیرفعال</span>
                    @endif

                </td>
                <td class="nk-tb-col nk-tb-col-tools">
                    <ul class="nk-tb-actions gx-1">
                        <li class="nk-tb-action-hidden">
                            {{-- <form method="POST" action="http://127.0.0.1:8000/admin/auth/user/2/mark/0" name="confirm-item" class="d-inline">
                            @csrf
                            <button typr="button" class="btn btn-trigger btn-icon" data-toggle="tooltip" data-placement="top" title=" غیرفعال کردن">
                                <em class="icon ni ni-wallet-fill"></em>
                            </button>
                        </form> --}}
                        </li>
                        <li class="nk-tb-action-hidden">
                            <button wire:click="selectItem({{$user->id}})" type="button" class="btn btn-trigger btn-icon" data-toggle="tooltip" data-placement="top" title="Send Email">
                                <em class="icon ni ni-mail-fill"></em>
                            </button>
                        </li>
                        <li class="nk-tb-action-hidden">
                            <a href="#" class="btn btn-trigger btn-icon" data-toggle="tooltip" data-placement="top" title="Suspend">
                                <em class="icon ni ni-user-cross-fill"></em>
                            </a>
                        </li>
                        <li>
                            <div class="drodown">
                                <a href="#" class="dropdown-toggle btn btn-icon btn-trigger" data-toggle="dropdown">
                                    <em class="icon ni ni-more-h"></em>
                                </a>
                                <div class="dropdown-menu dropdown-menu-right">
                                    <ul class="link-list-opt no-bdr">
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-focus"></em>
                                                <span>Quick View</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-eye"></em>
                                                <span>View Details</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-repeat"></em>
                                                <span>Transaction</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-activity-round"></em>
                                                <span>Activities</span>
                                            </a>
                                        </li>
                                        <li class="divider"></li>
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-shield-star"></em>
                                                <span>Reset Pass</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-shield-off"></em>
                                                <span>Reset 2FA</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="#">
                                                <em class="icon ni ni-na"></em>
                                                <span>Suspend User</span>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </li>
                    </ul>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>
<!-- Modal Content Code -->
<div class="modal fade" tabindex="-1" id="showUserModal" name="showUserModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <a href="#" class="close" data-dismiss="modal" aria-label="Close">
                <em class="icon ni ni-cross"></em>
            </a>
            <p id="idie" name="idie"></p>
            <div class="modal-header">
                <h5 class="modal-title">Modal Title</h5>
            </div>
            <div class="modal-body">
                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem similique earum necessitatibus nesciunt! Quia id expedita asperiores voluptatem odit quis fugit sapiente assumenda sunt voluptatibus atque facere autem, omnis explicabo.</p>
            </div>
            <div class="modal-footer bg-light">
                <span class="sub-text">Modal Footer Text</span>
            </div>
        </div>
    </div>
</div>

this is datatable code:

  NioApp.DataTable = function (elm, opt) {
    if ($(elm).exists()) {
      $(elm).each(function () {
        var auto_responsive = $(this).data('auto-responsive');
        var dom_normal = '<"row justify-between g-2"<"col-7 col-sm-6 text-left"f><"col-5 col-sm-6 text-right"<"datatable-filter"l>>><"datatable-wrap my-3"t><"row align-items-center"<"col-7 col-sm-12 col-md-9"p><"col-5 col-sm-12 col-md-3 text-left text-md-right"i>>';
        var dom_separate = '<"row justify-between g-2"<"col-7 col-sm-6 text-left"f><"col-5 col-sm-6 text-right"<"datatable-filter"l>>><"my-3"t><"row align-items-center"<"col-7 col-sm-12 col-md-9"p><"col-5 col-sm-12 col-md-3 text-left text-md-right"i>>';
        var dom = $(this).hasClass('is-separate') ? dom_separate : dom_normal;
        var def = {
          responsive: true,
          autoWidth: false,
          dom: dom,
          language: {
            search: "",
            searchPlaceholder: "برای جستجو تایپ کنید",
            lengthMenu: "<span class='d-none d-sm-inline-block'>نمایش</span><div class='form-control-select'> _MENU_ </div>",
            info: "_START_ -_END_ از _TOTAL_",
            infoEmpty: "اطلاعاتی یافت نشد",
            infoFiltered: "( مجموع _MAX_  )",
            paginate: {
              "first": "اول",
              "last": "قبلی",
              "next": "بعدی",
              "previous": "قبلی"
            }
          }
        },
            attr = opt ? extend(def, opt) : def;
        attr = auto_responsive === false ? extend(attr, {
          responsive: false
        }) : attr;
        $(this).DataTable(attr);
      });
    }
  };

and i added this code in layout view :

    @stack('before-scripts')
    <script src="/js/bundle.js?ver=2.2.0"></script>
    <script src="/js/scripts.js?ver=2.2.0"></script>

    @livewireScripts
    <script>
    window.addEventListener('name-updated', event => {
    $('#showUserModal').modal('show');
    $('#idie').text(event.detail.newName);
    });
    </script>
Activity icon

Started a new Conversation Open Modal In Livewire

hi guys i have a table for show users and i want a modal with user information is displayed when the administrator clicks on the user's display Is it possible to do this with LiveWire?

Mar
27
1 month ago
Activity icon

Started a new Conversation Indirect Modification Of Overloaded Property App\Models\frontend\Document::$selfie Has No Effect

This is a frequently asked question here, but it's the first time I'm encountering this problem And I saw other questions but I could not solve my problem. As far as I'm concerned I'm copying Laravel's documentation exactly, but I'm getting this error. I assume it's to do with the sub-relationships between models. Of course, I'm not sure What do you think is the problem?

my controller :

<?php

namespace App\Http\Livewire\Frontend;

use App\Models\frontend\Document as DocumentModel;
use Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Str;
use Livewire\Component;
use Livewire\WithFileUploads;

class Document extends Component
{
    use WithFileUploads;
    public $selfie;
    public $id_card;
    public $tc_agree;
    public $currect_information;

    public function sendDocument()
    {
        if ($document = auth()->user()->Document()->where('user_id', Auth::User()->id)->first()) {
            $doc = DocumentModel::where('user_id', Auth::user()->id)->first();

            if ($document->selfie['status'] !== 'accepted' && $document->selfie['status'][0] !== 'pending') {
                $this->validate([
                   'selfie' => 'required|mimes:jpg,jpeg,png|max:2024',
                   'tc_agree' => 'accepted',
                   'currect_information' => 'accepted',
                 ]);
                $selfie_url = $this->selfie->store('documents/'. Crypt::decryptString($document->secret));
                $doc->selfie['url'] = Crypt::encryptString($selfie_url);
                $doc->selfie['status'] = 'pending';
                $doc->selfie['desc'] = '';
                $doc->save();
            }
            if ($document->idcard['status'] != 'accepted' && $document->idcard['status'] != 'pending') {
                $this->validate([
                 'id_card' => 'required|mimes:jpg,jpeg,png|max:2024',
                  'tc_agree' => 'accepted',
                 'currect_information' => 'accepted',
               ]);
                $idcard_card = $this->id_card->store('documents/'. Crypt::decryptString($document->secret));
                $doc->idcard['url'] = Crypt::encryptString($idcard_card);
                $documdocent->idcard['status'] = 'pending';
                $doc->idcard['desc'] = '';
                $doc->save();
            }
        } else {
            $this->validate([
          'selfie' => 'required|mimes:jpg,jpeg,png|max:2024',
          'id_card' => 'required|mimes:jpg,jpeg,png|max:2024',
          'tc_agree' => 'accepted',
          'currect_information' => 'accepted',
        ]);
            $random = Str::random(35);
            $selfie_url = $this->selfie->store('documents/'.$random);
            $idcard_card = $this->id_card->store('documents/'.$random);
            DocumentModel::updateOrCreate([
          'user_id' => Auth::User()->id,
          'secret' => Crypt::encryptString($random),
          'selfie' => [
                'url' => Crypt::encryptString($selfie_url),
                'status' => 'pending',
                'last_update' => Carbon::now(),
                'desc' => '',
            ],
          'idcard' => [
              'url' => Crypt::encryptString($idcard_card),
              'status' => 'pending',
              'last_update' => Carbon::now(),
              'desc' => '',
            ],
        ]);
        }
    }


    public function render()
    {
        return view('livewire.frontend.document');
    }
}

and model:

    <?php

namespace App\Models\frontend;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Document extends Model
{
    use HasFactory;
    protected $table = "document";

    protected $fillable = [
           'id',
           'user_id',
           'secret',
           'selfie',
           'idcard',
       ];

    protected $casts = [
              'selfie' => 'array',
              'idcard' => 'array',
          ];



    public function user()
    {
        return $this->belongsTo('App\Domains\Auth\Models\User');
    }
}

Activity icon

Started a new Conversation Recieve Or Update Array Data

hi guys... i create a table and a column like this:

$table->json('data');

and this in Model :

protected $cast = [
'data' => 'array'
]

i can save data as array in table but how can i recieve or updata theme ?

Activity icon

Replied to Error 404 For Load Files

@snapey Only the administrator can see it and have access to it at any time

Activity icon

Replied to Error 404 For Load Files

So where should I put it The security of documents and the lack of access to anyone is very important

Activity icon

Replied to Error 404 For Load Files

what happend?

Activity icon

Replied to Error 404 For Load Files

@corvs yes i create storage link and my disk in local (i upload user's documents like id card or pssport and must use storage for secure)

Activity icon

Started a new Conversation Error 404 For Load Files

hi guys... i uploded images with storage like disk code:

$name = Storage::putFile('documents', $this->selfie);
      $path = $url = Storage::url($name);

      dd($path);

but i cant load images and returned error 404

Mar
25
1 month ago
Activity icon

Replied to Secure Uploaded Files

Where? Can you explain more, of course, with code? And do you think ‍‍storage/app it is not enough to create security?

Activity icon

Started a new Conversation Secure Uploaded Files

My users must upload their own identity documents such as their ID card or passport ... When these files are uploaded, anyone can easily access them in the public folder .. Where do you think these sensitive files should be uploaded? How not everyone can access them and how to secure them

Mar
24
1 month ago
Activity icon

Replied to Create Timer In Livewire

thanks bro... now How do I know if the function has been executes to show the timer in js?

Activity icon

Replied to Create Timer In Livewire

No, it is not a problem if it is not on the server side, because on the server side, the check may be over 60 seconds. How do I add a timestamp to a button? And how do I set the countdown timer? Can you give me a brief explanation with the code? (i want use livewire Because I used it everywhere )

Activity icon

Started a new Conversation Create Timer In Livewire

hi guys Suppose we have a button that, when clicked, executes a function. Now we want to put a timer instead of the text of the button when the button is clicked and that function is executed, for example 60 seconds and after 60 seconds the button returns to the original state and the user can click on it again. How can I do this with livewire? I'm sorry because I'm a novice, can you give me a brief explanation with the code?

Mar
23
1 month ago
Activity icon

Replied to Get The Distance Between Two Time

each user can have two record in this table (mobile number , home number (phone) ). When a code is generated, its expiration time is recorded for the next 60 seconds And if the user activation code has expired, that record will be deleted and By re-requesting a new record with the new activation code will be recorded in the table for the user. As I said, the expiration time of any code is 60 seconds after saving it And I changed the code that way :

if (Auth::User()->numberVerifies()->where('type','mobile')->exists()) {
               $expiry = optional(Auth::user()->numberVerifies()->where('type','mobile')->select('expire_at')->first())->expire_at;
               if ($expiry < Carbon::now()) {
                        $code = rand(11111, 99999);
                        numVerify::create([
                            'user_id' => Auth::User()->id,
                            'type' => 'mobile',
                            'code' => $code,
                            'expire_at' => Carbon::now()->addSecond(60)
                        ]);
                        
                        session()->flash('messageMobile', 'code created.');

               }
               elseif ($expiry > Carbon::now()) {
                  session()->flash('messageMobile', 'you have a code please try in 60 second later');
               }

           }

But still in both cases a new code is created

Activity icon

Replied to Get The Distance Between Two Time

migration :

    public function up()
    {
        Schema::enableForeignKeyConstraints();

        Schema::create('num_verify', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->enum('type',['mobile','phone']);
            $table->string('code');
            $table->timestamp("expire_at");
         
        });
        Schema::table('num_verify', function($table)
        {
            $table->foreign('user_id')->references('id')->on('users');
        });
    }

User model :

<?php

namespace App\Domains\Auth\Models;

use App\Domains\Auth\Models\Traits\Attribute\UserAttribute;
use App\Domains\Auth\Models\Traits\Method\UserMethod;
use App\Domains\Auth\Models\Traits\Relationship\UserRelationship;
use App\Domains\Auth\Models\Traits\Scope\UserScope;
use App\Domains\Auth\Notifications\Frontend\ResetPasswordNotification;
use App\Domains\Auth\Notifications\Frontend\VerifyEmail;
use DarkGhostHunter\Laraguard\Contracts\TwoFactorAuthenticatable;
use DarkGhostHunter\Laraguard\TwoFactorAuthentication;
use Database\Factories\UserFactory;
use Illuminate\Auth\MustVerifyEmail as MustVerifyEmailTrait;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Lab404\Impersonate\Models\Impersonate;
use Spatie\Permission\Traits\HasRoles;
use App\Models\frontend\numVerify;

/**
 * Class User.
 */
class User extends Authenticatable implements MustVerifyEmail, TwoFactorAuthenticatable
{
    use HasFactory,
        HasRoles,
        Impersonate,
        MustVerifyEmailTrait,
        Notifiable,
        SoftDeletes,
        TwoFactorAuthentication,
        UserAttribute,
        UserMethod,
        UserRelationship,
        UserScope;

    public const TYPE_ADMIN = 'admin';
    public const TYPE_USER = 'user';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'type',
        'name',
        'email',
        'email_verified_at',
        'password',
        'password_changed_at',
        'active',
        'timezone',
        'last_login_at',
        'last_login_ip',
        'to_be_logged_out',
        'provider',
        'provider_id',
        'balance',
        'mobile',
        'mobile_verify',
        'home_phone',
        'home_verify',
        'nat_id',
        'state',
        'city',
        'address',
        'zip_code',
        'document',
        'auth_level',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * @var array
     */
    protected $dates = [
        'last_login_at',
        'email_verified_at',
        'password_changed_at',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'active' => 'boolean',
        'last_login_at' => 'datetime',
        'email_verified_at' => 'datetime',
        'to_be_logged_out' => 'boolean',
    ];

    /**
     * @var array
     */
    protected $appends = [
        'avatar',
    ];

    /**
     * @var string[]
     */
    protected $with = [
        'permissions',
        'roles',
    ];

    /**
     * Send the password reset notification.
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token): void
    {
        $this->notify(new ResetPasswordNotification($token));
    }

    /**
     * Send the registration verification email.
     */
    public function sendEmailVerificationNotification(): void
    {
        $this->notify(new VerifyEmail);
    }

    /**
     * Return true or false if the user can impersonate an other user.
     *
     * @param void
     * @return  bool
     */
    public function canImpersonate(): bool
    {
        return $this->can('admin.access.user.impersonate');
    }

    /**
     * Return true or false if the user can be impersonate.
     *
     * @param void
     * @return  bool
     */
    public function canBeImpersonated(): bool
    {
        return ! $this->isMasterAdmin();
    }

    public function numberVerifies()
    {
        return $this->hasMany('App\Models\frontend\numVerify');
    }
    


    /**
     * Create a new factory instance for the model.
     *
     * @return \Illuminate\Database\Eloquent\Factories\Factory
     */
    protected static function newFactory()
    {
        return UserFactory::new();
    }
}

and number verification model:

<?php

namespace App\Models\frontend;

use App\Domains\Auth\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class numVerify extends Model
{
    use HasFactory;
    protected $table = "num_verify";

    protected $casts = [
    'expire_at' => 'datetime'
    ];


    public $timestamps = false;

    protected $fillable = [
        'id',
        'user_id',
        'type',
        'code',
        'expire_at'
    ];


    public function user()
    {
        return $this->belongsTo('App\Domains\Auth\Models\User');
    }
    

}

Activity icon

Replied to Get The Distance Between Two Time

thanks bro but this code in both cases return the enable. Do you have a better way to create an expiration time for mobile number verification code?

Activity icon

Replied to Get The Distance Between Two Time

what is optional?

Activity icon

Replied to Get The Distance Between Two Time

is timestamp

Activity icon

Started a new Conversation Get The Distance Between Two Time

I get the expire_at field of record (expire_at is timestamp field in table)

now i want check if expire_at time is It was bigger than it is now (Carbon::now()) in flash message show enable , otherwise show disable i use this code but it is wrong and show this error to me: Method Illuminate\Database\Eloquent\Collection::diffInMinutes does not exist.

my code:

if ( Auth::User()->numberVerifies()->where('type','mobile')->get('expire_at')->diffInMinutes(now()) > 1)
 {
             session()->flash('messageMobile', 'expire');
 }
else{
            session()->flash('messageMobile', 'enable');
        }