ToxifiedM

ToxifiedM

Member Since 2 Weeks Ago

Experience Points
430
Total
Experience

4,570 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.

Level 1
430 XP
Oct
26
5 days ago
Activity icon

Replied to Animate A Livewire Component Using AlpineJS

@sinnbeck Okay mate thanks! I'll give it a try.

Oct
25
6 days ago
Activity icon

Replied to Animate A Livewire Component Using AlpineJS

@sinnbeck please be useful, or somebody else can throw some light on it ?

Activity icon

Replied to Animate A Livewire Component Using AlpineJS

Included the modal component in the index.blade.php using the below piece of code.

@if($isOpen)
    @include('livewire.master-menu.menu-item-create')
@endif

Linked the event to the create button in the index.blade.php.

<button @click="isOpen = true" wire:click="showModal()">Create</button>

Then the usual code for the modal in the component which I want to animate. It shows up after I click the create button.

Borrowed the code for the modal component from here, https://tailwindui.com/preview#component-47a5888a08838ad98779d50878d359b3. I want the same animation as in the preview.

Activity icon

Started a new Conversation Animate A Livewire Component Using AlpineJS

How can I animate a livewire component using alpine.js. The button which opens the modal to create or update entries is in the index.blade.php view, when the button is clicked, it loads the livewire component for the modal i.e. create.blade.php. How can I give a transition to that element, on click of the button which is present in the index.blade.php. Sorry for being a noob, but I'm new to alpine. Experienced players, please help me!

Oct
23
1 week ago
Activity icon

Replied to Unable To Display A Single Instance Of Category, For Multiple Sub Categories Within The Foreach Loop

Thank for the revert mate, you are exactly right, I figured the same thing out, and its working as I expected it to. Thanks anyways, but no doubt you are right.

Oct
21
1 week ago
Activity icon

Started a new Conversation Unable To Display A Single Instance Of Category, For Multiple Sub Categories Within The Foreach Loop

I have a has many through eloquent relationship, between Categories->SubCategories->MenuItems. I need to display a single category for all the sub categories which falls under the category in specific. Instead of my expectations, its showing the category above each and every sub-category. Sorry for being a noob, please help me.

Here's what I have done so far.

<select wire:model="sub_category_id" class="form-select block w-full mt-1">
    <option>Select Sub Category</option>
    @foreach($menuitemlist as $menuitem)
    <optgroup label="{{ $menuitem->SubCategories->Categories->category_name }}">
        <option value="{{ $menuitem->SubCategories->id }}">{{ $menuitem->SubCategories->sub_category_name }}</option>
        @endforeach
        @error('sub_category_id') <h1 class="text-red-500">{{$message}}</h1>@enderror
</select>

This is the output which I am getting.

Oct
18
1 week ago
Activity icon

Replied to How Can I Conditionally Display The Input Select Box Based On The Radio Button Selected?

Sorry for the lengthy code. I hope this is what you need. :) I have improvised the above code further, and removed the extra stuff. Thanks already!

Activity icon

Replied to How Can I Conditionally Display The Input Select Box Based On The Radio Button Selected?

Yes I will surely go with alpine, thanks for the knowledge.

Here is the form in which I need to give that feature.

<form>
    <div>

        <div>
            <h1>CREATE POSTS</h1>
        </div>

        <div>

            <div>
                <input wire:model="itemId" type="hidden" placeholder="Input Post">
            </div>

            <!--Category ID-->
            <div>
                <label for="category_id">Category ID</label>
                <select wire:model="category_id" name="category_id" id="category_id">
                    <option value=""></option>
                    @foreach($categories as $category)
                    <option value="{{ $category->id }}">{{ $category->category_name }}</option>
                    @endforeach
                    @error('category_id') <h1>{{$message}}</h1>@enderror
                </select>
            </div>

            <!--Sub-Category ID-->
            <div>
                <label for="sub_category_id">Sub-Category ID</label>
                <select wire:model="sub_category_id" name="sub_category_id" id="sub_category_id">
                    <option value=""></option>
                    @foreach($subcategories as $subcategory)
                    <option value="{{ $subcategory->id }}">{{ $subcategory->sub_category_name }}</option>
                    @endforeach
                    @error('sub_category_id') <h1>{{$message}}</h1>@enderror
                </select>
            </div>

            <div>
                <label for="item_name">Item Name</label>
                <input wire:model="item_name" type="text" placeholder="Input Item Name">
                @error('item_name') <h1>{{$message}}</h1>@enderror
            </div>

            <div>
                <label for="item_description">Item Description</label>
                <textarea wire:model="item_description" name="item_description" placeholder="Input Item Description"></textarea>
                @error('item_description') <h1>{{$message}}</h1>@enderror
            </div>

        </div>

    </div>

    <div>
        <span>
            <button wire:click.prevent="store()" type="button">
                Submit
            </button>
        </span>
        <span>
            <button wire:click="hideModal()" type="button">
                Cancel
            </button>
        </span>
    </div>

</form>
Activity icon

Replied to How Can I Conditionally Display The Input Select Box Based On The Radio Button Selected?

Actually, I want to get the above result the Laravel way, which ever is better according to you. I am very much new to Laravel, if you can help me, I would be very much greatful.

Right now I on Laravel 8 with Livewire and Jetstream. I'm thinking to go with alpine.js.

Thanks for the revert! :)

Activity icon

Started a new Conversation How Can I Conditionally Display The Input Select Box Based On The Radio Button Selected?

I'm currently on Laravel 8. There are two input select boxes in a form, how can I conditionally display, either of the select boxes based on the radio button checked. I want to achieve the result without jQuery, please help me.

This is what I want to achieve:

Need to switch between these two:

<div class="mb-2">
    <label for="category_id" class="block">Category ID</label>
    <select wire:model="category_id" name="category_id" id="category_id" class="shadow appearance-none border rounded w-full py-2 px-3 text-blue-900">
        <option>Select Option</option>
        @foreach($categories as $category)
        <option value="{{ $category->id }}">{{ $category->category_name }}</option>
        @endforeach
        @error('category_id') <h1 class="text-red-500">{{$message}}</h1>@enderror
    </select>
</div>

<div class="mb-2">
    <label for="sub_category_id" class="block">Sub-Category ID</label>
    <select wire:model="sub_category_id" name="sub_category_id" id="sub_category_id" class="shadow appearance-none border rounded w-full py-2 px-3 text-blue-900">
        <option>Select Option</option>
        @foreach($subcategories as $subcategory)
        <option value="{{ $subcategory->id }}">{{ $subcategory->sub_category_name }}</option>
        @endforeach
        @error('sub_category_id') <h1 class="text-red-500">{{$message}}</h1>@enderror
    </select>
</div>
Activity icon

Awarded Best Reply on To Carry Out CRUD Operations For Multiple Tables In A Single View

I achieved the said above result by using the components feature in livewire, embedded the three components for three tables, without merging the controllers, clean and yet maintainable, thanks anyways :)

Activity icon

Replied to To Carry Out CRUD Operations For Multiple Tables In A Single View

I achieved the said above result by using the components feature in livewire, embedded the three components for three tables, without merging the controllers, clean and yet maintainable, thanks anyways :)

Oct
16
2 weeks ago
Activity icon

Replied to To Carry Out CRUD Operations For Multiple Tables In A Single View

Sure mate, thanks a lot! I'll give it a try and will get back to you.

Activity icon

Replied to To Carry Out CRUD Operations For Multiple Tables In A Single View

@loyd Hey Loyd, thanks for the revert! So I have separate controllers for all the three models. So I have initialized several functions for different operations. Lets take an example for the store operation function.

public function store(){
        $this->validate(
            [   
                'sub_category_id' => 'required',
                'item_name' => 'required',
            ]
        );

        MenuItem::updateOrCreate(['id' => $this->itemId], [
            'sub_category_id' => $this->sub_category_id,
            'item_name' => $this->item_name,
            'item_description' => $this->item_description
        ]);

        $this->hideModal();

        session()->flash('info', $this->itemId ? 'Post Update Successfully' : 'Post Created Successfully' );

        $this->itemId = '';
        $this->sub_category_id = '';
        $this->item_name = '';
        $this->item_description = '';
    }

So what I need to ask here is, do I need to merge the code from the other two controllers for the above operation under the public function store() or I can initialize the store function for the other controllers with a different name?

Activity icon

Started a new Conversation To Carry Out CRUD Operations For Multiple Tables In A Single View

I'm on Laravel 8 with Livewire, currently have 3 models, Category, SubCategory and MenuItem for 3 tables. All the above models have separate livewire controllers and have the code for the CRUD operations respectively. I have separate views and routes to edit the above tables and they all have a eloquent relationship between each other. Now what I need to do here to is, I need to display all the three tables in a single view to carry out the CRUD operations. Please help me with this. Thanks a lot for your time!

Oct
15
2 weeks ago
Oct
13
2 weeks ago
Activity icon

Started a new Conversation How To Post Data Variables From 2 Separate Livewire Components To A Single Blade File For CRUD Functionality?

Hey peeps, I wanted to post the variables initiated in the MenuItemList.php and SubCategoryList.php located in the App/Http/Livewire directory to a single blade file i.e. menu-item.blade.php. So I can further use the CRUD functionality for the above said tables i.e. menu-items and sub-categories from a single view, i.e. menu-item.blade.php.

When I run it through the different routes with separate views, it works flawlessly, but as soon as I try to combine them into one and try to view it all, in a single blade file, it gives me all sort of errors. Here is my source code. Please help me. Thanks already!

App\Models\MenuItem.php

<?php

namespace App\Models;

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

//Post
//MasterMenu
class MenuItem extends Model
{
    use HasFactory;

    protected $table = "menu_items";
    protected $fillable = ['sub_category_id', 'item_name', 'item_description'];
}

App\Http\Livewire\MenuItemList.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\MenuItem;

class MenuItemList extends Component
{
    use WithPagination;

    public $search;
    public $itemId,$sub_category_id,$item_name,$item_description;
    public $isOpen = 0;

    public function render()
    {       
        $searchParams = '%'.$this->search.'%';

        return view('livewire.menu-item', [
            'menuitemlist' => MenuItem::where('item_name','like', $searchParams)->latest()->paginate(5)
        ]);
    }

    public function showModal() {
        $this->isOpen = true;
    }

    public function hideModal() {
        $this->isOpen = false;
    }

    public function store(){
        $this->validate(
            [   
                'sub_category_id' => 'required',
                'item_name' => 'required',
            ]
        );

        MenuItem::updateOrCreate(['id' => $this->itemId], [
            'sub_category_id' => $this->sub_category_id,
            'item_name' => $this->item_name,
            'item_description' => $this->item_description
        ]);

        $this->hideModal();

        session()->flash('info', $this->itemId ? 'Post Update Successfully' : 'Post Created Successfully' );

        $this->itemId = '';
        $this->sub_category_id = '';
        $this->item_name = '';
        $this->item_description = '';
    }

    public function edit($id){
        $menuitem = MenuItem::findOrFail($id);
        $this->itemId = $id;
        $this->sub_category_id = $menuitem->sub_category_id;
        $this->item_name = $menuitem->item_name;
        $this->item_description = $menuitem->item_description;

        $this->showModal();
    }

    public function delete($id){
        MenuItem::find($id)->delete();
        session()->flash('delete','Post Successfully Deleted');
    }
}

App\Models\SubCategory.php

<?php

namespace App\Models;

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

class SubCategory extends Model
{
    use HasFactory;

    protected $table = "sub_categories";
    protected $fillable = ['category_id', 'sub_category_name'];
}

App\Http\Livewire\SubCategoryList.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\SubCategory;

class SubCategoryList extends Component
{
    use WithPagination;

    public $search;
    public $itemId,$category_id,$sub_category_name;
    public $isOpen = 0;

    public function render()
    {       
        $searchParams = '%'.$this->search.'%';

        return view('livewire.sub-category', [
            'subcategorylist' => SubCategory::where('sub_category_name','like', $searchParams)->latest()->paginate(5)
        ]);
    }

    public function showModal() {
        $this->isOpen = true;
    }

    public function hideModal() {
        $this->isOpen = false;
    }

    public function store(){
        $this->validate(
            [   
                'category_id' => 'required',
                'sub_category_name' => 'required',
            ]
        );

        SubCategory::updateOrCreate(['id' => $this->itemId], [
            'category_id' => $this->category_id,
            'sub_category_name' => $this->sub_category_name
        ]);

        $this->hideModal();

        session()->flash('info', $this->itemId ? 'Post Update Successfully' : 'Post Created Successfully' );

        $this->itemId = '';
        $this->category_id = '';
        $this->sub_category_name = '';
    }

    public function edit($id){
        $subcategory = SubCategory::findOrFail($id);
        $this->itemId = $id;
        $this->category_id = $subcategory->category_id;
        $this->sub_category_name = $subcategory->sub_category_name;

        $this->showModal();
    }

    public function delete($id){
        SubCategory::find($id)->delete();
        session()->flash('delete','Post Successfully Deleted');
    }
}

Routes\Web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Livewire\MenuItemList;
use App\Http\Livewire\SubCategoryList;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/menu-item', MenuItemlist::class);
Route::get('/sub-category', SubCategorylist::class);

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');
Oct
12
2 weeks ago
Activity icon

Replied to Getting "SQLSTATE[HY000]: General Error: 1364", For 'sub_category_id' As Well As 'item_description'.

When I am making the sub_category_id and the item_description required, the data is getting processed. Its working flawless but with the bellow adjusted code.

public function store(){
        $this->validate(
            [   'sub_category_id' => 'required',
                'item_name' => 'required',
                'item_description' => 'required',
            ]
        );

        MasterMenu::updateOrCreate(['id' => $this->itemId], [
            'sub_category_id' => $this->sub_category_id,
            'item_name' => $this->item_name,
            'item_description' => $this->item_description
        ]);
    }

But I don't want the sub_category_id and the item_description to be a required field, jut the item_name.

Activity icon

Started a new Conversation Getting "SQLSTATE[HY000]: General Error: 1364", For 'sub_category_id' As Well As 'item_description'.

Hey, I'm getting the following error, and I am unable to fix it, please help me.

SQLSTATE[HY000]: General error: 1364 Field 'sub_category_id' doesn't have a default value (SQL: insert into menu_items (item_name, updated_at, created_at) values (TEST, 2020-10-13 02:18:00, 2020-10-13 02:18:00))

I am trying to create a CRUD functionality with the following inputs, sub_category_id, item_name and item_description, I am unable to fix the error. When I mark it as nullable, it gets processed but there is no output for the sub_category_id and the item_description. Just item_name is being shown. Here is my markup.

App/Http/Livewire/MenuItem.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\MasterMenu;

//Posts
class MenuList extends Component
{
    use WithPagination;

    public $search;
    public $itemId,$sub_category_id,$item_name,$item_description;
    public $isOpen = 0;

    public function render()
    {       
        $searchParams = '%'.$this->search.'%';

        return view('livewire.menu-list', [
            'menulist' => MasterMenu::where('item_name','like', $searchParams)->latest()->paginate(5)
        ]);
    }

    public function showModal() {
        $this->isOpen = true;
    }

    public function hideModal() {
        $this->isOpen = false;
    }

    public function store(){
        $this->validate(
            [
                'item_name' => 'required'
            ]
        );

        MasterMenu::updateOrCreate(['id' => $this->itemId], [
            'item_name' => $this->item_name
        ]);

        $this->hideModal();

        session()->flash('info', $this->itemId ? 'Post Update Successfully' : 'Post Created Successfully' );

        $this->itemId = '';
        $this->sub_category_id = '';
        $this->item_name = '';
        $this->item_description = '';
    }

    public function edit($id){
        $mastermenu = MasterMenu::findOrFail($id);
        $this->itemId = $id;
        $this->sub_category_id = $mastermenu->sub_category_id;
        $this->item_name = $mastermenu->item_name;
        $this->item_description = $mastermenu->item_description;

        $this->showModal();
    }

    public function delete($id){
        MasterMenu::find($id)->delete();
        session()->flash('delete','Post Successfully Deleted');
    }
}

App/Models/MasterMenu.php

<?php

namespace App\Models;

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

//Post
class MasterMenu extends Model
{
    use HasFactory;

    protected $table = "menu_items";
    protected $fillable = ['sub_category_id', 'item_name', 'item_description'];
}

Database/Migrations/create_menu_items_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

//CreatePostsTable
class CreateMenuItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('menu_items', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('sub_category_id');
            $table->string('item_name');
            $table->text('item_description');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('menu_items');
    }
}