Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

Randy_Johnson

Randy_Johnson

Member Since 2 Years Ago

Experience Points
9,290
Total
Experience

710 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
9
Lessons
Completed
Best Reply Awards
1
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.

Level 2
9,290 XP
Nov
21
3 days ago
Activity icon

Started a new Conversation Eloquent - Explanation Inside

Since I am grabbing all my information for the user in one line of code, it makes a lot of sense for me to do the vise versa.

$users = User::with(['roles', 'images', 'userDetails'])->get();

When creating a user from the admin panel I have it as suck.

 // Creates a new user
        User::create([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            'password' => Hash::make($request->input('password')),
        ]);

        // Grabs the user which we just created
        $user = User::where('email', $request->input('email'))->first();

        // Assign the user the selected role
        $user->assignRole($request->input('role'));

        // Enters the users details into the user_details table
        UserDetails::create([
            'user_id' => $user->id,
            'address' => $request->input('address'),
            'telephone' => $request->input('telephone'),
        ]);

But I am thinking that surely this can be done all at once and save the confusion.

Please help.

Nov
20
4 days ago
Activity icon

Replied to Eloquent Not Working

I just copied the db name. I have no idea how the eloquent works. Its like a magic box.

Activity icon

Replied to Eloquent Not Working

I found the problem - didn't have

use App\Models\Image;

Why it wasn't showing it as an error I don't know but I fear it had something to do with the try catch statement.

Activity icon

Started a new Conversation Eloquent Not Working

I have a database table called 'images' and a model called 'Image' but when I run

Image::create([
                'user_id' => $user->id,
                'url' => 'storage/img/user/'.$imageName
            ]);

Nothing happens. Running the next command works perfectly.

DB::table('images')->insert([
                'user_id' => $user->id, 
                'url' => 'storage/img/user/'.$imageName
            ]);
Activity icon

Replied to Pluck() Grabbing All Images Instead Of Just One

$user->images->url

Actually it was this simple. wtf is wrong with me.

Activity icon

Replied to Pluck() Grabbing All Images Instead Of Just One

Okay thank you. But it is very strange that I was using

{{$user->roles->pluck('name')->implode('')}}

and it was working fine. This is why I was so confused about the matter. Thank you, your way is much more suited.

Activity icon

Replied to Pluck() Grabbing All Images Instead Of Just One

and I cannot understand, clearly from the code I am wanting only 1 image corresponding to the user, as $user. Why is it returning all of them, that just stupid.

Activity icon

Replied to Pluck() Grabbing All Images Instead Of Just One

{{$user->images->pluck('url')->implode('')->first()}}

This is not working.

It is just giving me

syntax error, unexpected '<' (View: C:\Users\Josh\Desktop\Projects\spatie-permissions\resources\views\includes\users-table.blade.php) (View: C:\Users\Josh\Desktop\Projects\spatie-permissions\resources\views\includes\users-table.blade.php) 
Activity icon

Replied to Pluck() Grabbing All Images Instead Of Just One

Why can I not find this in the laravel documentation.

Activity icon

Started a new Conversation Pluck() Grabbing All Images Instead Of Just One

When using the Eloquent Pluck functionality, it is returning all the fields within the database under url.

+++ Returning String +++

storage/img/user/1605882108.jpegstorage/img/user/1605881403.jpegstorage/img/user/user.png

+++ Single Code +++

{{$user->images->pluck('url')->implode('')}}

+++ Blade HTML Full Page +++

<div>
    @php
        $i = 0;
    @endphp
    <!-- Users Table -->
    <div class="card-body">
        <table class="table table-striped">
            <thead class="thead-dark">
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">Name</th>
                    <th scope="col">Email</th>
                    <th scope="col">Role</th>
                    <th scope="col">Updated at</th>
                    <th scope="col"></th>
                </tr>
            </thead>
            <tbody>
                @foreach($data['users'] as $user)
                    <tr>
                        <td>{{$user->id}}</td>
                        <td>{{$user->name}}</td>
                        <td>{{$user->email}}</td>
                        <td>{{$user->roles->pluck('name')->implode('')}}</td>
                        <td>{{$user->updated_at}}</td>
                        <td>
                            <div class="float-right">
                                <button class="btn btn-warning" data-toggle="modal" data-target="#userUpdateModal{{$i}}">Show</button>
                                <form class="d-inline" action="{{route('user.destroy', $user->id)}}" method="POST">
                                    @csrf 
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-danger" data-toggle="confirmation">Delete</button>
                                </form>
                            </div>
                        </td>
                    </tr>

                    {{-- Update user form --}}
                    <form action="{{route('user.update', $user->id)}}" method="POST" enctype="multipart/form-data">
                        @csrf
                        @method('PATCH')
                        <div class="modal" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="">Update</h5>
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                        <div classs="form-group">
                                            <img src="" alt="{{$user->images->pluck('url')->implode('')}}" class="img-thumbnail rounded p-2 mb-2">
                                        </div>
                                        <div class="form-group">
                                            <label for="">Name</label>
                                            <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="name" value="{{$user->name}}" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="">Email</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="email" value="{{$user->email}}" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="">Address</label>
                                            <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="" placeholder="Buckingham Palace, London, England" name="address" value="">
                                        </div>
                                        <div class="form-group">
                                            <label for="">Telephone No.</label>
                                            <input type="tel" class="form-control bfh-phone" data-format="+dd (ddd) ddd-dddd" placeholder="" name="telephone" value="">
                                        </div>
                                        <div class="form-group">
                                            <label for="">Role</label>
                                            <select class="form-control" id="sel1" name="role" required>
                                                <option value="1">Admin</option>
                                                <option value="2">Teacher</option>
                                                <option value="3">Parent</option>
                                                <option value="4">Student</option>
                                            </select>
                                        </div>
                                        <div class="form-group files">
                                            <label for="">Upload Image</label>
                                            <input type="file" class="form-control" name="image">
                                        </div>                                              
                                    </div>
                                    <div class="modal-footer">
                                        <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                        <button type="submit" class="btn btn-primary">
                                            Update
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>

                    @php
                        $i++;
                    @endphp
                @endforeach
            </tbody>
        </table>
        
    </div>
</div>
Nov
19
5 days ago
Activity icon

Replied to Livewire Trying To Get Property 'name' Of Non-object

when show is being clicked. The vars are passing, just the box doesn't appear correctly.

App\Models\User {#1432 ▼
  #fillable: array:3 [▶]
  #hidden: array:2 [▶]
  #casts: array:1 [▶]
  #connection: "mysql"
  #table: "users"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:8 [▶]
  #original: array:8 [▼
    "id" => 1
    "name" => "Admin"
    "email" => "[email protected]"
    "email_verified_at" => null
    "password" => "y$BJGGZ6tM2MvwQLiJeeEUQOlCIEKU5tmSZgnzXeIlRR1GF/zWtvChq"
    "remember_token" => null
    "created_at" => "2020-11-18 10:25:40"
    "updated_at" => "2020-11-18 10:25:40"
  ]
Activity icon

Replied to Livewire Trying To Get Property 'name' Of Non-object

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\User;

class UpdateUser extends Component
{
    public $userId;

    protected $listeners = ['getId'];

    public function getId($id) 
    {
        $this->userId = $id;
    }

    public function store() { }

    public function render()
    {   
        if (!isset($this->userId)) {
            $user = new User();
            $user->name = "User";
            $user->email = "[email protected]";
        } else {
            $user = User::find($this->userId);
        }
        return view('livewire.update-user')->with('user', $user);
    }
}

Now the window just goes blank when I click show.

Activity icon

Replied to Livewire Trying To Get Property 'name' Of Non-object

    protected $listeners = ['getId'];

    public function getId($id) 
    {
        dd($this->$userId = $id);
    }
<button class="btn btn-warning" data-toggle="modal" data-target="#userUpdateModal" wire:click="$emit('getId', $user->id)">Show</button>

This doesn't seem to be firing and I have no idea why, it was firing earlier.

Activity icon

Replied to Livewire Trying To Get Property 'name' Of Non-object

I fixed it but now when clicking show, it is show user name as user when it should be looking up the actual user with

$user = User::find($this->userId);

which leads me to believe that

wire:click="$emit('getId', $user->id)"

is not working correctly. I will update soon.

Activity icon

Started a new Conversation Livewire Trying To Get Property 'name' Of Non-object

I am terrible sorry that this isn't resolving its self as efficiently as I would like but I have now run into another problem.

+++ Error +++

Trying to get property 'name' of non-object (View: C:\Users\Josh\Desktop\Projects\spatie-permissions\resources\views\livewire\update-user.blade.php) (View: C:\Users\Josh\Desktop\Projects\spatie-permissions\resources\views\livewire\update-user.blade.php) 

+++ Livewire Component Controller +++

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\User;

class UpdateUser extends Component
{
    public $userId;
    public $user;

    protected $listeners = ['getId'];

    public function getId($id) 
    {
        $this->$UserId = $id;
    }

    public function store() { }

    public function render()
    {   
        if (!empty($this->userId)) {
            $user = new User();
            $user->name = "User";
            $user->email = "[email protected]";
        } else {
            $user = User::find($this->userId);
        }
        return view('livewire.update-user')->with('user', $user);
    }
}

+++ Livewire Blade View +++

{{ $user->name }}
Nov
18
6 days ago
Activity icon

Replied to Livewire, Passing ID From The Form

Create a new post.

Activity icon

Replied to Livewire, Passing ID From The Form

Having a guess I would have the modal as a livewire component and then have it open as such.

A little direction would be great. I wasted hours trying to do it before and reverted everything back.

Nov
17
1 week ago
Activity icon

Replied to Livewire Error On Form - Freezing Screen

Hi, I tried both to no avail. P.S. I did correct the code. Thank you mvd.

Activity icon

Started a new Conversation Livewire Error On Form - Freezing Screen

I am creating a user creation form using livewire, and I am running into the problem of when opening the form and clicking a input field, typing information and clicking out, it freezes and shows the error below.

+++ Error +++

Property [name] does not exist on the create-user component. 

Inside the livewire component controller I input the variables to prevent this error, but when trying the previous tasks, now the screen just freezes and no error message appears.

Here is my code.

+++ Livewire Component Controller +++

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class CreateUser extends Component
{
    public $name;
    public $email;
    public $address;
    public $telephone;
    public $password;
    public $passwordConfirmed;
    public $role;
    public $image;

    public function render()
    {
        return view('livewire.create-user');
    }
}

+++ Livewire Blade +++

<div>
    <!-- Create User -->
    <form wire:submit.prevent="store()">
        @csrf 
        <div class="modal fade" id="userCreateModal" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="">Create</h5>
                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="">Name</label>
                            <input type="text" class="form-control" wire:model="name" required>
                        </div>
                        <div class="form-group">
                            <label for="">Email</label>
                            <input type="email" class="form-control" wire:model="email" required>
                        </div>
                        <div class="form-group">
                            <label for="">Address</label>
                            <input type="text" class="form-control" value="" placeholder="Buckingham Palace, London, England" wire:model="address">
                        </div>
                        <div class="form-group">
                            <label for="">Telephone</label>
                            <input type="tel" class="form-control input-medium bfh-phone" data-format="+dd (ddd) ddd-dddd" wire:model="telephone">
                        </div>
                        <div class="form-group">
                            <label for="">Password</label>
                            <input type="password" class="form-control" wire:model=" name"wire:model="password" required>
                        </div>
                        <div class="form-group">
                            <label for="">Password Confirmation</label>
                            <input type="password" class="form-control" wire:model="password-confirm" required>
                        </div>
                        <div class="form-group">
                            <label for="">Role</label>
                            <select class="form-control" wire:model="role" required>
                                <option value="1">Admin</option>
                                <option value="2">Teacher</option>
                                <option value="3">Parent</option>
                                <option value="4">Student</option>
                            </select>
                        </div>
                        <div class="form-group files">
                            <label for="">Upload Image</label>
                            <input type="file" class="form-control" wire:model="image">
                        </div>                                              
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary">
                            Update
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
Activity icon

Replied to Livewire, Passing ID From The Form

I was messing around, and I was getting some weird errors due to weird reason such as using a global var (not super global) instead of a local. The page is now showing but I am still in the same predicament of the variables not showing within the update form.

+++ Full Component Controller ++

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;

use Illuminate\Http\Request;
use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Session\SessionManager;


use DB;

use App\Models\User;
use App\Models\UserDetails;

use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

use App\Http\Controllers\ImageController;
use App\Http\Controllers\UserDetailsController;


class UsersTable extends Component
{
    use WithPagination;

    protected $paginationTheme = 'bootstrap';

    public $name;
    public $email;
    public $address;
    public $telephone;
    public $role;
    public $image;

    public function mount()
    {
        $users = User::with(['roles', 'images', 'userDetails'])->get();
    }

    public function render()
    {        
        $users = User::with(['roles', 'images', 'userDetails'])->get();

        return view('livewire.users-table', [
            'users' => User::paginate(10),
        ]);
    }

    public function update($id)
    {
        $user = User::find($id);
        $userDetails = UserDetails::where('user_id', $id)->first();

        $user->name = $this->name;
        $user->email = $this->email;

        if (!empty($this->address)) {
            $userDetails->address = $this->address;
        } 
        
        if (!empty($this->telephone)) {
            $userDetails->telephone = $this->telephone; 
        }  

        try {
            $image = new ImageController();
            $image->store($this->image, $id);
        }
        catch (exception $e) {
            return session()->flash('message', 'User did not updated successfully.');
        }
        finally {
            $user->save();
            $userDetails->save();
            DB::table('model_has_roles')
              ->where('model_id', $id)
              ->update(['role_id' => $this->role]);
            return session()->flash('message', 'User successfully updated.');
        }
    }
}

+++ Full Livewire Blade +++

@php
    $i = 1;
@endphp

<div>
    <!-- Users Table -->
    <div class="card-body">
        <table class="table table-striped">
            <thead class="thead-dark">
                <tr>
                    <th scope="col">Name</th>
                    <th scope="col">Email</th>
                    <th scope="col">Role</th>
                    <th scope="col">Updated at</th>
                    <th scope="col"></th>
                </tr>
            </thead>
            <tbody>
                @foreach($users as $user)
                <tr>
                    <td>{{$user->name}}</td>
                    <td>{{$user->email}}</td>
                    <td>{{$user->roles->pluck('name')->implode('')}}</td>
                    <td>{{$user->updated_at}}</td>
                    <td>
                        <div class="float-right">
                            <a class="btn btn-warning" href="#" data-toggle="modal" data-target="#userUpdateModal{{$i}}">Show</a>
                            <form class="d-inline" action="{{ route('user.destroy', $user->id) }}" method="POST">
                                @csrf 
                                @method('DELETE')
                                <button type="submit" class="btn btn-danger" data-toggle="confirmation">Delete</button>
                            </form>
                        </div>
                    </td>
                </tr>

                <!-- Update User -->
                <form wire:submit.prevent="update({{$user->id}})">
                    @csrf 
                    @method('PATCH')
                    <div class="modal fade" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="">Update</h5>
                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <div classs="form-group">
                                        <img src="{{asset($user->images->pluck('url')->implode(''))}}" alt="..." class="img-thumbnail rounded p-2 mb-2">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Name</label>
                                        <input name="name" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$user->name}}" wire:model="name">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Email</label>
                                        <input name="email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$user->email}}" wire:model="email">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Address</label>
                                        <input name="address" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="" value="{{$user->userDetails->pluck('address')->implode('')}}" placeholder="Buckingham Palace, London, England" wire:model="address">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Telephone No.</label>
                                        <input name="telephone" type="tel" class="form-control input-medium bfh-phone" value="{{$user->userDetails->pluck('telephone')->implode('')}}" data-format="+dd (ddd) ddd-dddd" placeholder="" wire:model="telephone">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Role</label>
                                        <select name="role" class="form-control" id="sel1"  wire:model="role">
                                            <option value="1">Admin</option>
                                            <option value="2">Teacher</option>
                                            <option value="3">Parent</option>
                                            <option value="4">Student</option>
                                        </select>
                                    </div>
                                    <div class="form-group files">
                                        <label for="">Upload Image</label>
                                        <input name="image" type="file" class="form-control" multiple="" wire:model="image">
                                    </div>                                              
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-primary">
                                        Update
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

                @php 
                    $i++; 
                @endphp 
                
                @endforeach
            </tbody>
        </table>
        {{ $users->links() }}
    </div>
</div>
Nov
16
1 week ago
Activity icon

Replied to Livewire, Passing ID From The Form

Yes, I am sorry I made a mistake, but I do have a problem in that the inputs are empty now on opening them and are not containing the data needed.

It happens when I put wire:model="" into the input fields.

Activity icon

Started a new Conversation Livewire, Passing ID From The Form

Hi, I am trying to pass an ID so I can update a user.

+++ Livewire +++

public function update($id)
    {
        $user = User::find($id);
        $userDetails = UserDetails::where('user_id', $id)->first();

        $user->name = $this->name;
        $user->email = $this->email;

        if (!empty($this->address)) {
            $userDetails->address = $this->address;
        } 
        
        if (!empty($this->telephone)) {
            $userDetails->telephone = $this->telephone; 
        }  

        try {
            $image = new ImageController();
            $image->store($this->image, $id);
        }
        catch (exception $e) {
            return session()->flash('message', 'User did not updated successfully.');
        }
        finally {
            $user->save();
            $userDetails->save();
            DB::table('model_has_roles')
              ->where('model_id', $id)
              ->update(['role_id' => $this->role]);
            return session()->flash('message', 'User successfully updated.');
        }
    }

+++ HTML +++

<form wire:submit.prevent="update({{$user->id}})">
                    @csrf 
                    @method('PATCH')
                    <div class="modal fade" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="">Update</h5>
                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <div classs="form-group">
                                        <img src="{{asset($user->images->pluck('url')->implode(''))}}" alt="..." class="img-thumbnail rounded p-2 mb-2">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Name</label>
                                        <input name="name" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$user->name}}">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Email</label>
                                        <input name="email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$user->email}}">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Address</label>
                                        <input name="address" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="" value="{{$user->userDetails->pluck('address')->implode('')}}" placeholder="Buckingham Palace, London, England">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Telephone No.</label>
                                        <input name="telephone" type="tel" class="form-control input-medium bfh-phone" value="{{$user->userDetails->pluck('telephone')->implode('')}}" data-format="+dd (ddd) ddd-dddd" placeholder="">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Role</label>
                                        <select name="role" class="form-control" id="sel1"  wire:model="role">
                                            <option value="1">Admin</option>
                                            <option value="2">Teacher</option>
                                            <option value="3">Parent</option>
                                            <option value="4">Student</option>
                                        </select>
                                    </div>
                                    <div class="form-group files">
                                        <label for="">Upload Image</label>
                                        <input name="image" type="file" class="form-control" multiple="">
                                    </div>                                              
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-primary">
                                        Update
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

+++ Error +++

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: update `users` set `name` = ?, `email` = ?, `users`.`updated_at` = 2020-11-16 22:01:56 where `id` = 1) 
Activity icon

Started a new Conversation Livewire Forms

I am trying to use a form just as I would in php, but in livewire, I am having trouble with the request.

++ Livewire Component ++

    public function update(Request $request, $id)
    {
        $user = User::find($id);
        $user->name = $request->input('name');
        $user->email = $request->input('email');

        $userDetails = UserDetails::where('user_id', $id)->first();

        if (!empty($request->input('address'))) {
            $userDetails->address = $request->input('address');
        } 
        
        if (!empty($request->input('telephone'))) {
            $userDetails->telephone = $request->input('telephone'); 
        }  

        try {
            $image = new ImageController();
            $image->store($request, $id);
        }
        catch (exception $e) {
            return redirect()->route('user.index')->withFail('User failed to update!');
        }
        finally {
            $user->save();
            $userDetails->save();
            DB::table('model_has_roles')
              ->where('model_id', $id)
              ->update(['role_id' => $request->input('role')]);
            return  session()->flash('message', 'User successfully updated.');;
        }
    }

++ HTML ++

                <form wire:submit.prevent="update({{$user->id}})" enctype="multipart/form-data">
                    @csrf 
                    @method('PATCH')
                    <div class="modal fade" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="">Update</h5>
                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <div classs="form-group">
                                        <img src="{{asset($user->images->pluck('url')->implode(''))}}" alt="..." class="img-thumbnail rounded p-2 mb-2">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Name</label>
                                        <input name="name" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$user->name}}" />
                                    </div>
                                    <div class="form-group">
                                        <label for="">Email</label>
                                        <input name="email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$user->email}}" />
                                    </div>
                                    <div class="form-group">
                                        <label for="">Address</label>
                                        <input name="address" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="" value="{{$user->userDetails->pluck('address')->implode('')}}" placeholder="Buckingham Palace, London, England"/>
                                    </div>
                                    <div class="form-group">
                                        <label for="">Telephone No.</label>
                                        <input name="telephone" type="tel" class="form-control input-medium bfh-phone" value="{{$user->userDetails->pluck('telephone')->implode('')}}" data-format="+dd (ddd) ddd-dddd" placeholder="">
                                    </div>
                                    <div class="form-group">
                                        <label for="">Role</label>
                                        <select name="role" class="form-control" id="sel1">
                                            <option value="1">Admin</option>
                                            <option value="2">Teacher</option>
                                            <option value="3">Parent</option>
                                            <option value="4">Student</option>
                                        </select>
                                    </div>
                                    <div class="form-group files">
                                        <label for="">Upload Image</label>
                                        <input name="image" type="file" class="form-control" multiple="">
                                    </div>                                              
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-primary">
                                        Update
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

++ Error ++

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: update `users` set `name` = ?, `email` = ?, `users`.`updated_at` = 2020-11-16 17:14:11 where `id` = 1) 
Nov
09
2 weeks ago
Activity icon

Replied to Chart.js Passing Data

I figured it out. It was simple I dont know why I couldnt before.

It didnt help that I didnt give all the code in the post either.

data['specificData']

Nov
07
2 weeks ago
Activity icon

Started a new Conversation Chart.js Passing Data

I am passing data from laravel into js. The problem is I cannot figure out how to access that data.

<script>
    var data = {!! json_encode($data) !!};
    alert(data[0]);    <--- This is returning a non object. I check this online for accessing variables.
    var ctx = document.getElementById('myChart').getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ['Admin', 'Teacher', 'Parent', 'Student'],
            datasets: [{
                label: 'User by Role amount',
                data: [12, 19, 3, 5],
                backgroundColor: [
                    'rgba(255, 99, 132, 0.2)',
                    'rgba(54, 162, 235, 0.2)',
                    'rgba(255, 206, 86, 0.2)',
                    'rgba(75, 192, 192, 0.2)'
                ],
                borderColor: [
                    'rgba(255, 99, 132, 1)',
                    'rgba(54, 162, 235, 1)',
                    'rgba(255, 206, 86, 1)',
                    'rgba(75, 192, 192, 1)'
                ],
                borderWidth: 1
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true
                    }
                }]
            }
        }
    });
</script>
Nov
06
2 weeks ago
Activity icon

Replied to Should I Learn HTML And CSS Before Going Into Django?

You will find your own way, but if you want to be a single full stack dev - all paths lead to Laravel.

Activity icon

Replied to Call To Undefined Relationship

Thank you, I was doing it in the wrong controller.

Activity icon

Started a new Conversation Call To Undefined Relationship

Help, I have having this problem with a relationship, but I do not know much about Eloquent. I tried doing the relationship thing within the model, to no avail. I also have a $table->foreignId('user_id')->constrained()->onDelete('cascade'); constraint on the images table. Which I thought would of solved the problem.

I am clueless.

Call to undefined relationship
$users = User::with(['roles', 'images'])->get();
Nov
04
2 weeks ago
Activity icon

Replied to Non-static Method

I forgot to mention that the top one is ImageController and the bottom one is UserController.

Activity icon

Started a new Conversation Non-static Method

    public function store(Request $request)
    {
        $request->validate($request, [
            'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
  
        $imageName = time().'.'.$request->image->extension();  
   
        $request->image->move(public_path('images'), $imageName);
    }
    public function update(Request $request, $id)
    {
        ImageController::store($request);

        $user = User::find($id);
        $user->name = $request->input('name');
        $user->email = $request->input('email');
        DB::table('model_has_roles')
              ->where('model_id', $id)
              ->update(['role_id' => $request->input('role')]);
        $user->save();
        return redirect()->route('user.index');
    }
Nov
03
3 weeks ago
Activity icon

Replied to I Broke Register (Registering Account)

Massive thank you, I have no idea how it even happened but the second password field name was set to password and not password_confirmation.

Activity icon

Started a new Conversation I Broke Register (Registering Account)

I was messing inside my registerController and now when I try to create a new account it just returns to the register page with nothing done, no db add.

I copied and pasted from another file so the registercontroller is the same as the before but I am still getting this weird thing.

In the network tab I am getting a 302 response.

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = "/dashboard/user";

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\Models\User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}
Nov
02
3 weeks ago
Activity icon

Replied to Adding Dropdown In Registration

laravel new blog --auth

Activity icon

Replied to Adding Dropdown In Registration

Laravel Framework 8.9.0 Auth was installed using Laravel new blog --auth. I am not using JetStream or anything like that.

Activity icon

Started a new Conversation Adding Dropdown In Registration

Hi, I have added a drop down menu in the registration page and was wondering how I go about implementing it. Inside the RegistrationController I have noticed that there are the main variables being passed through an array, I want my drop down menu data to be placed inside the $data being send through the parameters.

    protected function create(array $data)
    {
        dd($data);
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }

Laravel Framework 8.9.0 Auth was installed using Laravel new blog --auth

Nov
01
3 weeks ago
Activity icon

Started a new Conversation DB How To Get Data From A Collection Relationship

        $data = User::with('roles')->get();

        return view('dashboard.show-users')->with('data', $data);
                        @foreach($data as $datum)
                        <tr>
                            <td>{{$datum->name}}</td>
                            <td>{{$datum->email}}</td>
                            <td>{{$datum->roles['id']}}</td>
                            <td>{{$datum->updated_at}}</td>
                            <td>

I am having trouble accessing the roles name.

Activity icon

Replied to DB Wanted Data Not Appearing Through JOIN

I am using a foreach

@foreach($data as $datum)
                        <tr>
                            <td>{{$datum->name}}</td>
                            <td>{{$datum->email}}</td>
                            <td>{{$datum->roles['name']}}</td>
                            <td>{{$datum->updated_at}}</td>
                            <td>
Activity icon

Replied to DB Wanted Data Not Appearing Through JOIN

How do I get the role name is blade.

                            <td>{{$datum->name}}</td>
                            <td>{{$datum->email}}</td>
                            <td>{{$datum->roles['name']}}</td>   <--------????
                            <td>{{$datum->updated_at}}</td>
Activity icon

Replied to DB Wanted Data Not Appearing Through JOIN

Yes, I think I understand, because of the linking of the data through migration, I am able to do this. Correct?

Activity icon

Started a new Conversation DB Wanted Data Not Appearing Through JOIN

I am using Spatie Permissions and Roles, I want to return the role name but it isn't appearing.

$data = DB::table('users')
            ->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')
            ->join('roles', 'model_has_roles.role_id', '=', 'roles.id')
            ->select('users.*', 'model_has_roles.*', 'roles.*')
            ->get();
Illuminate\Support\Collection {#1393 ▼
  #items: array:1 [▼
    0 => {#1399 ▼
      +"id": 1
      +"name": "admin"
      +"email": "[email protected]"
      +"email_verified_at": null
      +"password": "5452352352352344DDASSFAGDGDAGDASGDGASDGASGASFFASDFAGH34TDAG"
      +"remember_token": null
      +"created_at": "2020-11-01 21:42:02"
      +"updated_at": "2020-11-01 21:42:02"
      +"role_id": 1
      +"model_type": "App\Models\User"
      +"model_id": 1
      +"guard_name": "web"
    }
  ]
}
Activity icon

Replied to DB Column Not Found!?

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_has_roles.modal_id' in 'on clause' (SQL: select `users`.*, `model_has_roles`.* from `users` inner join `model_has_roles` on `users`.`id` = `model_has_roles`.`model_id`)

Sorry guys, it was really strange because I had changed that error, but it didn't refresh just right, I don't know why.

Activity icon

Started a new Conversation DB Column Not Found!?

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_has_roles.modal_id' in 'on clause' (SQL: select `users`.*, `model_has_roles`.* from `users` inner join `model_has_roles` on `users`.`id` = `model_has_roles`.`modal_id`) 
        $data = DB::table('users')
            ->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')
            ->select('users.*', 'model_has_roles.*')
            ->get();
+---------+-----------------+----------+
| role_id | model_type      | model_id |
+---------+-----------------+----------+
|       1 | App\Models\User |        1 |
+---------+-----------------+----------+
+-----------------------+
| Tables_in_school      |
+-----------------------+
| attendances           |
| failed_jobs           |
| fees                  |
| grades                |
| injuries              |
| migrations            |
| model_has_permissions |
| model_has_roles       |
| password_resets       |
| payments              |
| permissions           |
| reports               |
| role_has_permissions  |
| roles                 |
| subjects              |
| time_tables           |
| users                 |
+-----------------------+
Oct
31
3 weeks ago
Activity icon

Replied to Having Data Shown In The Modal When Opening.

I think some of the code is missing. Its running in a foreach loop.

@extends('layouts.dashboard')

@section('title', 'English Learning')

@section('content')    

@php
    $i = 1;
@endphp

<div class="col-xl-12 col-lg-12">
    <div class="card shadow mb-4">
    <!-- Card Header - Dropdown -->
    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
        <h6 class="m-0 font-weight-bold text-primary">Users</h6>
        <div class="dropdown no-arrow">
        <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
        </a>
        <div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
            <div class="dropdown-header">Database Actions:</div>
            <a class="dropdown-item" href="#">Drop</a>
            <a class="dropdown-item" href="#">Truncate</a>
        </div>
        </div>
            </div>
            <!-- Card Body -->
            <div class="card-body">
                <table class="table">
                    <thead>
                        <tr>
                        <th scope="col">#</th>
                        <th scope="col">Name</th>
                        <th scope="col">Email</th>
                        <th scope="col">Create at</th>
                        <th scope="col"></th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data as $datum)
                            <tr>
                            <th scope="row">{{$datum->id}}</th>
                            <td>{{$datum->name}}</td>
                            <td>{{$datum->email}}</td>
                            <td>{{$datum->created_at}}</td>
                            <td>
                                <div class="float-right"> 
                                    <a class="btn btn-warning" href="#" data-toggle="modal" data-target="#userUpdateModal{{$i}}">Update</a>
                                    <form class="d-inline" action="{{ route('user.destroy', $datum->id) }}" method="POST">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger" data-toggle="confirmation">Delete</button>
                                    </form>
                                </div>
                            </td>
                            </tr>

                            <form action="{{ route('user.update', $datum->id)}}" method="POST">
                                @csrf
                                @method('PATCH')
                                <div class="modal fade" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                        <h5 class="modal-title" id="exampleModalLabel">Update</h5>
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        </div>
                                        <div class="modal-body">
                                            <div class="form-group">
                                                <label for="exampleInputEmail1">Name</label>
                                                <input name="name" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$datum->name}}">
                                            </div>  
                                            <div class="form-group">
                                                <label for="exampleInputEmail1">Email</label>
                                                <input name="email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{$datum->email}}">
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                        <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                        <button type="submit" class="btn btn-primary">
                                            Update
                                        </button>
                                        </div>
                                    </div>
                                    </div>
                                </div>
                            </form>

                            @php 
                                $i++;
                            @endphp

                        @endforeach
                    </tbody>
                </table>
        </div>
    </div>
</div>

@endsection
Activity icon

Awarded Best Reply on Having Data Shown In The Modal When Opening.

@extends('layouts.dashboard')

@section('title', 'English Learning')

@section('content')

{!! $i = 1; !!}

Users
Database Actions: Drop Truncate # Name Email Create at @foreach($data as $datum) {{$datum->id}} {{$datum->name}} {{$datum->email}} {{$datum->created_at}} Update @csrf @method('DELETE') Delete
                        <form action="{{ route('user.update', $datum->id)}}" method="POST">
                            @csrf
                            @method('PATCH')
                            <div class="modal fade" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                    <h5 class="modal-title" id="exampleModalLabel">Update</h5>
                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                    </div>
                                    <div class="modal-body">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Email</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" value="{{$datum->email}}">
                                        </div>  
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Email</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputPassword1">Password</label>
                                            <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Picture</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                    <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-primary">
                                        Update
                                    </button>
                                    </div>
                                </div>
                                </div>
                            </div>
                        </form>

                        {!! $i++ !!}

                    @endforeach
                </tbody>
            </table>
    </div>
</div>

@endsection

Activity icon

Replied to Having Data Shown In The Modal When Opening.

@extends('layouts.dashboard')

@section('title', 'English Learning')

@section('content')

{!! $i = 1; !!}

Users
Database Actions: Drop Truncate # Name Email Create at @foreach($data as $datum) {{$datum->id}} {{$datum->name}} {{$datum->email}} {{$datum->created_at}} Update @csrf @method('DELETE') Delete
                        <form action="{{ route('user.update', $datum->id)}}" method="POST">
                            @csrf
                            @method('PATCH')
                            <div class="modal fade" id="userUpdateModal{{$i}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                    <h5 class="modal-title" id="exampleModalLabel">Update</h5>
                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                    </div>
                                    <div class="modal-body">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Email</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" value="{{$datum->email}}">
                                        </div>  
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Email</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputPassword1">Password</label>
                                            <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Picture</label>
                                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                    <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-primary">
                                        Update
                                    </button>
                                    </div>
                                </div>
                                </div>
                            </div>
                        </form>

                        {!! $i++ !!}

                    @endforeach
                </tbody>
            </table>
    </div>
</div>

@endsection

Activity icon

Started a new Conversation Having Data Shown In The Modal When Opening.

When updating a user I have a Modal dialog box appearing. I want the users data to be shown in the input box when the Modal is opened.

How would I go about doing that and do you have a link to a good tutorial.

Oct
29
3 weeks ago
Activity icon

Started a new Conversation Delete Not Working

Sorry guys don't mean to be posting so much but this has me miffered.

http://127.0.0.1:8000/dashboard/user/1

<a class="btn btn-danger" data-toggle="confirmation" href="{{route('user.destroy', $datum->id)}}">Delete</a>

public function destroy($id)
{
    $data = User::find($id);
    $data->delete();
    return redirect()->route('user.index');
}
Activity icon

Started a new Conversation Update Method Redirect Not Working.

I am running the code below and in the URL I am getting ... with a blank page.

http://127.0.0.1:8000/dashboard/user/1?_token=hUXoXGZFLI50lYl05QcbeRQdL0qpGCHZIk5k1ze5&_method=PATCH
    public function update(Request $request, $id)
    {
        return redirect()->route('user.index');
    }
<form action="{{ route('user.update', $datum->id)}}">
                                @csrf
                                @method('PATCH')
                                <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                        <h5 class="modal-title" id="exampleModalLabel">Update</h5>
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        </div>
                                        <div class="modal-body">Update something blah .</div>
                                        <div class="modal-footer">
                                        <a class="btn btn-secondary" data-dismiss="modal">Cancel</a>
                                        <button type="submit" class="btn btn-primary">
                                            Update
                                        </button>
                                        </div>
                                    </div>
                                    </div>
                                </div>
                            </form>
Activity icon

Replied to Bootstrap Modal Help - Route Link Not Working

I will need it to be a form to send data, I just change to a form and put in a button type button, with the form using a route, but when clicking the button, nothing happens.


@extends('layouts.dashboard')

@section('title', 'English Learning')

@section('content')    

<!-- Area Chart -->
<div class="col-xl-12 col-lg-12">
    <div class="card shadow mb-4">
    <!-- Card Header - Dropdown -->
    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
        <h6 class="m-0 font-weight-bold text-primary">Users</h6>
        <div class="dropdown no-arrow">
        <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
        </a>
        <div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
            <div class="dropdown-header">Database Actions:</div>
            <a class="dropdown-item" href="#">Drop</a>
            <a class="dropdown-item" href="#">Truncate</a>
        </div>
        </div>
            </div>
            <!-- Card Body -->
            <div class="card-body">
                <table class="table">
                    <thead>
                        <tr>
                        <th scope="col">#</th>
                        <th scope="col">Name</th>
                        <th scope="col">Email</th>
                        <th scope="col">Create at</th>
                        <th scope="col"></th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data as $datum)
                            <tr>
                            <th scope="row">{{$datum->id}}</th>
                            <td>{{$datum->name}}</td>
                            <td>{{$datum->email}}</td>
                            <td>{{$datum->created_at}}</td>
                            <td>
                                <div class="text-right"> 
                                    <a class="btn btn-warning" href="#" data-toggle="modal" data-target="#updateModal"">Update</a>
                                    <button class="btn btn-danger" data-toggle="confirmation" href="{{route('user.destroy', $datum->id)}}">Delete</button>
                                </div>
                            </td>
                            </tr>

                            <!-- Logout Modal-->
                            <form action="{{ route('user.update', $datum->id), $datum->id }}"></form>
                                <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                        <h5 class="modal-title" id="exampleModalLabel">Update</h5>
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        </div>
                                        <div class="modal-body">Update something blah .</div>
                                        <div class="modal-footer">
                                        <a class="btn btn-secondary" data-dismiss="modal">Cancel</a>
                                        <button type="submit" class="btn btn-primary">
                                            Update
                                        </a>
                                        </div>
                                    </div>
                                    </div>
                                </div>
                            </form>




                        @endforeach
                    </tbody>
                </table>
        </div>
    </div>
</div>

@endsection
Activity icon

Started a new Conversation Bootstrap Modal Help - Route Link Not Working

@extends('layouts.dashboard')

@section('title', 'English Learning')

@section('content')    

<!-- Area Chart -->
<div class="col-xl-12 col-lg-12">
    <div class="card shadow mb-4">
    <!-- Card Header - Dropdown -->
    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
        <h6 class="m-0 font-weight-bold text-primary">Users</h6>
        <div class="dropdown no-arrow">
        <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
        </a>
        <div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
            <div class="dropdown-header">Database Actions:</div>
            <a class="dropdown-item" href="#">Drop</a>
            <a class="dropdown-item" href="#">Truncate</a>
        </div>
        </div>
            </div>
            <!-- Card Body -->
            <div class="card-body">
                <table class="table">
                    <thead>
                        <tr>
                        <th scope="col">#</th>
                        <th scope="col">Name</th>
                        <th scope="col">Email</th>
                        <th scope="col">Create at</th>
                        <th scope="col"></th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data as $datum)
                            <tr>
                            <th scope="row">{{$datum->id}}</th>
                            <td>{{$datum->name}}</td>
                            <td>{{$datum->email}}</td>
                            <td>{{$datum->created_at}}</td>
                            <td>
                                <div class="text-right"> 
                                    <a class="btn btn-warning" href="#" data-toggle="modal" data-target="#updateModal"">Update</a>
                                    <button class="btn btn-danger" data-toggle="confirmation" href="{{route('user.destroy', $datum->id)}}">Delete</button>
                                </div>
                            </td>
                            </tr>

                            <!-- Logout Modal-->
                            <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                    <h5 class="modal-title" id="exampleModalLabel">Update</h5>
                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                    </div>
                                    <div class="modal-body">Update something blah .</div>
                                    <div class="modal-footer">
                                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                                    <button class="btn btn-primary" href="#" data-toggle="modal" data-target="#updateModal" href="{{ route('welcome') }}">
                                        Update
                                    </button>
                                    </div>
                                </div>
                                </div>
                            </div>




                        @endforeach
                    </tbody>
                </table>
        </div>
    </div>
</div>

@endsection