kkhicher1

kkhicher1

PHP Developer at Home

Member Since 9 Months Ago

Experience Points
3,470
Total
Experience

1,530 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
1
Lessons
Completed
Best Reply Awards
3
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
3,470 XP
Jul
31
2 weeks ago
Activity icon

Replied to Upload An Image Using Drag & Drop Over A Placeholder Image.

sure, you will get false because you haven't a image type like png, jpg for any other file type. its send a base64 string data that's why we need to convert that string data into image file

if you dd($request->image_file) you will get a big random string of base64... that why yo need to convert or decode your file from base64.

you can try and reply

Activity icon

Replied to Upload An Image Using Drag & Drop Over A Placeholder Image.

okay.... now to need to know about base64_decode() php function....

You can use below method for upload a base64 image in your controller

Ex..

$url = $this->uploadImageFromBase64($request->your_image, 'path/to/store/image_name');

$url you can store this to your database

decode image and store url to database

protected function uploadImageFromBase64($image, $filename)
    {
        $exploded = explode (',', $image);
        $decodedImage = base64_decode($exploded[1]);

        if (\str_contains($exploded[0], 'jpg'))
            $extension = 'jpg';
        else
            $extension = 'png';

        if ($decodedImage) {
            $profile = $path. '.' . $extension;
            \file_put_contents($profile, $decodedImage);
        } else {
            $profile = 'default.png';
        }
        return $profile;
    }

base64 validation

protected function base64Check($image){
        try {
            $image = explode('/', $image);
            return $image[0] === 'data:image';
        }catch(\Exception $e ){
            return false;
        }
    }

ex. use of base64 image validation

if ($this->base64Check($request->image)) {
            $category->image()->create([
                'url'       => $this->uploadImageFromBase64($request->your_image, 'path/to/store/image_name');
            ]);
  }
Activity icon

Started a new Conversation Store Extra Data With Payment Gateway Response

Hi, I just implement Indipay package and im using payumoney payment gateway.

in my transaction table i have some column like, user_id, billing_id and package_id all are foreign key.

Schema::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id');
            $table->foreignId('package_id');
            $table->foreignId('billing_id');
            $table->unsignedBigInteger('amount');
            $table->text('txnid');
            $table->text('productinfo')->nullable();
            $table->string('status')->nullable();
            $table->timestamps();
        });

i want to save user_id, billing_id and package_id for future use.

when payment gateway return success on another url i handle response on [email protected] method but we not get user_id, billing_id and package_id in that response. so how i fill that field ?

public function store(Request $request)
    {
	$response = Indipay::response($request);
        $txn = new Transaction();
        $txn->user_id = auth()->id();
	$txn->save();
}

#routes

Route::post('/indipay/response/success', "[email protected]");
Jul
19
3 weeks ago
Activity icon

Replied to Fetch Model's Nested Relationship Data

okay i got solution... the code was okay....

Jul
18
4 weeks ago
Activity icon

Replied to Fetch Model's Nested Relationship Data

ya i have all these columns in table

Activity icon

Replied to Fetch Model's Nested Relationship Data

User.php

<?php

namespace App;

use App\Casts\CreateAtCast;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, HasRoles;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

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

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'created_at'        => CreateAtCast::class,
    ];

    protected $dates = ['created_at', 'updated_at'];

    //relationship
    public function image()
    {
        return $this->morphOne(Image::class, 'imageable');
    }

    public function customer(){
        return $this->hasOne(Customer::class);
    }

    public function packages()
    {
        return $this->belongsToMany(Package::class)->withPivot('location_name');
    }
}

Packages.php

<?php

namespace App;

class Package extends Model
{

    protected $fillable = ['name', 'price', 'description', 'bandwidth'];

    public function billings()
    {
        return $this->hasMany(Billing::class);
    }

    public function users()
    {
        return $this->belongsToMany(User::class);
    }
}

Customer.php

<?php

namespace App;

class Customer extends User
{
    protected $fillable = ['user_id', 'first_name', 'last_name', 'address', 'status', 'phone'];

    //relationship

    public function user(){
        return $this->belongsTo(User::class);
    }
}

Activity icon

Started a new Conversation Fetch Model's Nested Relationship Data

i have customer model that is one to one relationship with user and a user has many to many relationship with packages. i want to get data from customer with user packages

return Customer::with('user', 'user.image', 'user.packages')->paginate(10);

like the code above

its return package an empty array but i have 2 row in my package_user table that i already in relationship with user and package.

Jul
15
1 month ago
Activity icon

Awarded Best Reply on Accessing Laravel Json Response In Vue Didn't Receiving The Message

Your Code look fine. can you share your request from browser's dev tool network tab....

Activity icon

Replied to Accessing Laravel Json Response In Vue Didn't Receiving The Message

Your Code look fine. can you share your request from browser's dev tool network tab....

Jul
01
1 month ago
Activity icon

Replied to Laravel Api

share your code

May
26
2 months ago
Activity icon

Replied to How Do I Upload Images To My Heroku App In Laravel

did you check that your symlink folder in public folder created or not?

Activity icon

Replied to BelongsToMany Between Pivot Model And Regular Model

your ArticleSite haven't dossier_id column. You may try hasManyThrough Method in your model.

Check Full Article Here => https://laravel.com/docs/7.x/eloquent-relationships#has-many-through

May
22
2 months ago
Activity icon

Replied to Update OneToMany Relationship Table Data With Limit

from this

$count = 0;

        foreach ($user->pins as $pin) {
            if ($count == $request->no_of_pin) {
                if ($pin->status == 'available') {
                    $pin->user_id = $transfer_user->id;
                    $pin->save();
                    $count++;
                }
            }
        }
Activity icon

Replied to Update OneToMany Relationship Table Data With Limit

code work but i want eloquent way to done this task

May
21
2 months ago
Activity icon

Started a new Conversation Update OneToMany Relationship Table Data With Limit

I want to update oneToMany Reationship table data with limit and also where status is available....

$count = 0;

        foreach ($user->pins as $pin) {
            if ($count == $request->no_of_pin) {
                if ($pin->status == 'available') {
                    $pin->user_id = $transfer_user->id;
                    $pin->save();
                    $count++;
                }
            }
        }

May
18
2 months ago
Activity icon

Started a new Conversation Mood Off ! What You Do When It Happen?

as a developer i think its happen many time that your mood off to make a single module and write some code. I want to know how to overcome from this situation that i start coding again..

May
17
2 months ago
Activity icon

Awarded Best Reply on Laravel + Vue - Populate Select After API Call With Axios

you need to change your v-model of select

<select v-model="selected.person">

    <option v-for="person in persons" :value="person.id">
        {{ person.fullname_with_year }}
    </option>

</select>
<script>
    export default {

        data() {
            return {
                persons: [],
		selected:{
			person:''
		}
            }
        },

        mounted() {
            this.getPersons();
        },

        methods: {
            getPersons(){
                console.log('getPersons');
                axios.get('/api/persons/all')
                    .then((response) => {
                        console.log( response.data );
                        this.persons = response.data;

                    })
                    .catch( resonse => {
                        console.log('error');
                    })
            },
        }
    }
</script>

try this

May
16
2 months ago
Activity icon

Replied to Array To String Conversion

okay, but that is solution.... i want to know why that error return ....

Activity icon

Replied to Array To String Conversion

error return on this line =>

if (is_null($this->sponserTree->$columns[$i]))
Activity icon

Replied to Array To String Conversion

oh sorry,,,, that was typo error,,,,, now check

Activity icon

Replied to Laravel + Vue - Populate Select After API Call With Axios

you need to change your v-model of select

<select v-model="selected.person">

    <option v-for="person in persons" :value="person.id">
        {{ person.fullname_with_year }}
    </option>

</select>
<script>
    export default {

        data() {
            return {
                persons: [],
		selected:{
			person:''
		}
            }
        },

        mounted() {
            this.getPersons();
        },

        methods: {
            getPersons(){
                console.log('getPersons');
                axios.get('/api/persons/all')
                    .then((response) => {
                        console.log( response.data );
                        this.persons = response.data;

                    })
                    .catch( resonse => {
                        console.log('error');
                    })
            },
        }
    }
</script>

try this

Activity icon

Started a new Conversation Array To String Conversion

can anybody elaborate the below function throw error Array to string conversion but same thing work if i put in a variable.....

this throw error

// column name - id, user_id, left_1, left_2, right_1, right_2
$columns = Schema::getColumnListing('sponser_trees');
        if ($this->sponserTree != null) {
            for ($i = 2; $i <= 5; $i++) {
                if (is_null($this->sponserTree->$columns[$i])) {
                    return $columns[$i];
                }
            }
        } else {
            return 'left_1';
        }

its work fine;;;;

// column name - id, user_id, left_1, left_2, right_1, right_2
$columns = Schema::getColumnListing('sponser_trees');
        if ($this->sponserTree != null) {
            for ($i = 2; $i <= 5; $i++) {
                $col = (string) $columns[$i];
                if (is_null($this->sponserTree->$col)) {
                    return $col;
                }
            }
        } else {
            return 'left_1';
        }
Activity icon

Started a new Conversation Fire Parent Method On Child Component Value Change Vuejs

i want to fire a parent method on child component value change...

##parent component

<template>
  <div class="bg-gray-200 h-full">
    <header-view></header-view>
    <div class="px-32 py-6">
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Id nemo quam voluptates tenetur atque, similique odio quasi assumenda, quo porro deleniti eos nobis officia tempore, at harum odit. Illo, doloribus.</p>
    </div>
    <h2 class="text-2xl text-center about">Apply for Subsidy</h2>
    <div class="w-full h-full flex justify-center mt-16">
      <form class="w-full max-w-lg">
        <text-input id="name" placeholder="Enter Name" title="Name"></text-input>
        <text-input id="fathername" placeholder="Enter Father Name" title="Father Name"></text-input>
        <text-input id="phone" placeholder="Enter Active Mobile No" title="Mobile No"></text-input>
        <text-input id="aadhar" placeholder="Enter Aadhar No" title="Aadhar No"></text-input>
        <text-input id="accountno" placeholder="Enter Account No" title="Bank Account No"></text-input>
        <text-input
          id="ifsc"
          placeholder="Enter IFSC Code"
          title="Bank Branch IFSC Code"
          v-model="data.ifsc"
          @change="getIfscCode(data.ifsc)"
        ></text-input>
        <text-input id="accountname" placeholder="Enter Account Name" title="Bank Account Name"></text-input>
      </form>
    </div>
    <footer-view></footer-view>
  </div>
</template>

<script>
import HeaderView from "./header/Header";
import FooterView from "./footer/Footer";
import TextInput from "./form/TextInput";
export default {
  components: {
    HeaderView,
    FooterView,
    TextInput
  },
  data() {
    return {
      data: {
        name: "",
        ifsc: ""
      }
    };
  },
  created() {},
  methods: {
    getIfscCode(code) {
      axios
        .get(
          "https://mfapps.indiatimes.com/ET_Calculators/getBankDetailsByIfsc.htm?ifsccode=" +
            code +
            "&callback=objIFSC.getIfscData"
        )
        .then(res => {
          console.log(res.data);
        });
    }
  }
};
</script>

##child component

<template>
  <div class="flex flex-wrap mb-6">
    <div class="w-full px-3">
      <label
        class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2"
        :for="id"
      >{{title}}</label>
      <input
        class="appearance-none block w-full bg-gray-900 p-text-color border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500 placeholder-blue-300"
        :id="id"
        type="text"
        :placeholder="placeholder"
        :value="inputvalue"
        @input="$emit('update', $event.target.value)"
      />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String
    },
    id: {
      type: String
    },
    placeholder: {
      type: String
    },
    inputvalue: undefined
  },
  model: {
    prop: "inputvalue",
    event: "update"
  }
};
</script>
May
10
3 months ago
Activity icon

Awarded Best Reply on Images In Public Folder.

very simple steps....

first create a temp. route to call a artisan command

Route::get('/symlink', function () {
    Artisan::call('storage:link');
});

then open browser and go to url -> http://example.com/symlink ========> only once

then check your public folder linked or not

hope its help..... if not reply this conversation

Activity icon

Replied to Images In Public Folder.

select a best answer so in feature other can get solution as fast as possible.

Activity icon

Replied to Https Routes Not Working

use code at the top of web.php

<?php 

use Illuminate\Support\Facades\URL;

if (env('APP_ENV') === 'production') {
    URL::forceScheme('https');
}

if you are using cloudflare try to add page rule

hope it help

Activity icon

Replied to Images In Public Folder.

very simple steps....

first create a temp. route to call a artisan command

Route::get('/symlink', function () {
    Artisan::call('storage:link');
});

then open browser and go to url -> http://example.com/symlink ========> only once

then check your public folder linked or not

hope its help..... if not reply this conversation

Activity icon

Replied to Test Single Pass But Fail When I Test All

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <server name="APP_ENV" value="testing"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="sqlite"/>
        <server name="DB_DATABASE" value=":memory:"/>
        <server name="MAIL_MAILER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="DB_CONNECTION" value="mysql"/>
        <server name="DB_DATABASE" value="laravel7"/>
    </php>
</phpunit>

Activity icon

Replied to Form Request, Validation On Update

this is not developer friendly.... you should have only one request method on store and update ....... for this you can try

$on_update = $this->method() == "PUT" ? ','.$this->id : '';
return [
	'email'		=> 'required|unique:clients,id'.$on_update
];

this is will work both update and store method

May
09
3 months ago
Activity icon

Replied to Can Someone Help Me Out

@tomasosho => as per @guybrush_threepwood it's very simple process to store file into your storage folder or public folder.... 1st you have to decide where you want to store then implement the code...

Activity icon

Replied to Can Someone Help Me Out

first (in your controller method)

dd($request->avatar)  

if you get big string value then you need to decode your base64 image with php base64_decode function

base64_decode ( string $data [, bool $strict = false ] ); 

its a php function you can use in your controller...

Hope its help

Activity icon

Replied to Test Single Pass But Fail When I Test All

as i think..... when i run whole test total row will be 4. so in last method a_book_can_check_out_a_book_twice the Reservation::find(2) isn't exist because their may be id 3 and 4 exist ( when test all ) but on single test Reservation::find(2) return object that's why is success on single test? ? ? / ?

what you think?

Activity icon

Started a new Conversation Test Single Pass But Fail When I Test All

<?php

namespace Tests\Unit;

use App\Book;
use App\User;
use Tests\TestCase;
use App\Reservation;
use Exception;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class BookReservationTest extends TestCase
{
    use RefreshDatabase;
    /**
     * @test
     */
    public function a_book_can_be_checked_out()
    {
        // $book->checkout($user);
        $book = \factory(Book::class)->create();
        $user = \factory(User::class)->create();


        $book->checkout($user);

        $this->assertCount(1, Reservation::all());
        $this->assertEquals($user->id, Reservation::first()->user_id);
        $this->assertEquals($book->id, Reservation::first()->book_id);
        $this->assertEquals(now(), Reservation::first()->checked_out_at);
    }

    /**
     * @test
     */
    public function a_book_can_be_returned()
    {
        $book = \factory(Book::class)->create();
        $user = \factory(User::class)->create();

        $book->checkout($user);


        $book->checkin($user);

        $this->assertCount(1, Reservation::all());
        $this->assertEquals($user->id, Reservation::first()->user_id);
        $this->assertEquals($book->id, Reservation::first()->book_id);
        $this->assertEquals(now(), Reservation::first()->checked_in_at);
    }
    /**
     * @test
     */
    public function if_not_checked_out_exception_is_thrown()
    {
        $this->expectException(Exception::class);
        $book = \factory(Book::class)->create();
        $user = \factory(User::class)->create();

        $book->checkin($user);
    }
    /**
     * @test
     */
    public function a_book_can_check_out_a_book_twice()
    {
        $book = \factory(Book::class)->create();
        $user = \factory(User::class)->create();

        $book->checkout($user);
        $book->checkin($user);

        $book->checkout($user);


        $this->assertCount(2, Reservation::all());
        $this->assertEquals($user->id, Reservation::find(2)->user_id);
        $this->assertEquals($book->id, Reservation::find(2)->book_id);
        $this->assertNull(Reservation::find(2)->checked_in_at);
        $this->assertEquals(now(), Reservation::find(2)->checked_out_at);

        $book->checkin($user);

        $this->assertCount(2, Reservation::all());
        $this->assertEquals($user->id, Reservation::find(2)->user_id);
        $this->assertEquals($book->id, Reservation::find(2)->book_id);
        $this->assertNotNull(Reservation::find(2)->checked_in_at);
        $this->assertEquals(now(), Reservation::find(2)->checked_in_at);
    }
}

when i run test a_book_can_check_out_a_book_twice with filter it pass but when i run phpunit its fail and return error

1) Tests\Unit\BookReservationTest::a_book_can_check_out_a_book_twice
ErrorException: Trying to get property 'user_id' of non-object
Apr
18
3 months ago
Activity icon

Replied to How To Store Image In Laravel 7.4.0?

very simple----

save to storage

if ($request->hasFile('product_photo')) {
            // Get filename with extension            
            $filenameWithExt = $request->file('product_photo')->getClientOriginalName();
            // Get just filename
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            // Get just ext
            $extension = $request->file('product_photo')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename . '_' . time() . '.' . $extension;
            // Upload Image
            $path = $request->file('product_photo')->storeAs('public/product-photos', $fileNameToStore);
        }

to store in db

$product = Model::create([
	'product_photo_name' => $fileNameToStore,
]);
Activity icon

Replied to How To Use DiffForHumans() In Vue

I got the solution that you can use anywhere with casting attribute. Check Code below

<?php

namespace App\Casts;

use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class CreateAtCast implements CastsAttributes
{
    /**
     * Transform the attribute from the underlying model values.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $key
     * @param  mixed  $value
     * @param  array  $attributes
     * @return mixed
     */
    public function get($model, string $key, $value, array $attributes)
    {
        $date = Carbon::parse($value)->diffForHumans();
        return $date;
    }

    /**
     * Transform the attribute to its underlying model values.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $key
     * @param  mixed  $value
     * @param  array  $attributes
     * @return array
     */
    public function set($model, string $key, $value, array $attributes)
    {
        return $value;
    }
}

in Modal


<?php

namespace App;

use App\Casts\CreateAtCast;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    protected $casts = [
        'email_verified_at' => 'datetime',
        'created_at'        => CreateAtCast::class,
    ];

    protected $dates = ['created_at', 'updated_at'];
}


in vue template just use - user.create_at

Apr
13
4 months ago
Activity icon

Replied to Checkbox Custom Component Value Not Updating VUE JS

I tried this temp. solution. is it okay?

<template>
  <div>
    <div class="form-group" v-if="type != 'checkbox'">
      <label v-bind:for="id">{{labelText}}</label>
      <input
        v-bind:type="type"
        class="form-control"
        v-bind:id="id"
        v-bind:placeholder="placeholder"
        autocomplete="off"
        :value="inputvalue"
        @input="$emit('update', $event.target.value)"
      />
      <small class="form-text text-danger" v-if="errorMsg">{{errorMsg}}</small>
    </div>

    <div class="form-group ml-4 form-check-inline" v-if="type == 'checkbox'">
      <input
        v-bind:id="id"
        class="form-check-input"
        v-bind:type="type"
        :value="checkboxvalue"
        @change="onCheckboxChange"
      />
      <label class="form-check-label" v-bind:for="id">{{labelText}}</label>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    id: String,
    labelText: String,
    type: String,
    placeholder: String,
    errorMsg: String,
    checkboxvalue: Number,
    inputvalue: undefined
  },
  model: {
    prop: "inputvalue",
    event: "update"
  },
  methods: {
    onCheckboxChange(e) {
      if (e.target.checked) {
        this.$emit("update", e.target.value);
      } else {
        this.$emit("update", null);
      }
    }
  }
};
</script>
Activity icon

Replied to Checkbox Custom Component Value Not Updating VUE JS

I tried both but result same..

Apr
12
4 months ago
Activity icon

Started a new Conversation Checkbox Custom Component Value Not Updating VUE JS

I make reusable checkbox custom element with vue. but i got problem. when i select i got the value but when uncheck instant my value not change to default.

My Custom Input Vue

<template>
  <div>
    <div class="form-group" v-if="type != 'checkbox'">
      <label v-bind:for="id">{{labelText}}</label>
      <input
        v-bind:type="type"
        class="form-control"
        v-bind:id="id"
        v-bind:placeholder="placeholder"
        autocomplete="off"
        :value="inputvalue"
        @input="$emit('update', $event.target.value)"
      />
      <small class="form-text text-danger" v-if="errorMsg">{{errorMsg}}</small>
    </div>

    <div class="form-group ml-4 form-check-inline" v-if="type == 'checkbox'">
      <input
        v-bind:id="id"
        class="form-check-input"
        v-bind:type="type"
        :value="checkboxvalue"
        @input="$emit('update', $event.target.value)"
      />
      <label class="form-check-label" v-bind:for="id">{{labelText}}</label>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    id: String,
    labelText: String,
    type: String,
    placeholder: String,
    errorMsg: String,
    checkboxvalue: undefined,
    inputvalue: undefined
  },
  model: {
    prop: "inputvalue",
    event: "update"
  },
  methods: {}
};
</script>

My Parent Vue

<template>
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12">
        <button
          class="btn btn-primary btn-round"
          data-toggle="modal"
          data-target="#add-role"
        >Add New Role</button>
        <button
          class="btn btn-primary btn-round"
          data-toggle="modal"
          data-target="#add-permission"
        >Add New Permission</button>

        <!-- modals -->
        <!-- role modal -->
        <pop-modal
          title="Add New Role"
          id="add-role"
          btn-title="Save Role"
          v-bind:saveData="saveRole"
        >
          <input-modal
            id="name"
            label-text="Role Name"
            placeholder="Enter Role Name"
            type="text"
            v-model="data.name"
          ></input-modal>
          <p>
            <strong>Select Permission</strong>
          </p>
          <input-modal
            v-for="(permission, index) in permissions"
            :id="`permission-input-`+ permission.id"
            :label-text="permission.name"
            type="checkbox"
            :checkboxvalue="permission.id"
            v-model="data.ids[index]"
            :key="permission.id"
          ></input-modal>
        </pop-modal>
        <!-- permission Modal -->
        <pop-modal title="Add New Permission" id="add-permission" v-bind:saveData="savePermission">
          <input-modal
            id="name"
            label-text="Permission Name"
            placeholder="Enter Permission Name"
            type="text"
          ></input-modal>
        </pop-modal>
      </div>
      <div class="col-md-6">
        <h3 class="border-bottom border-primary">Roles</h3>
        <div class>
          <table class="table table-hover table-bordered">
            <tr>
              <th>Role Name</th>
              <th>Guard</th>
              <th>Actions</th>
            </tr>
            <tr v-for="role in roles">
              <td>{{role.name}}</td>
              <td>{{role.guard_name}}</td>
              <td>
                <button class="btn btn-warning btn-sm">Edit</button>
                <button class="btn btn-danger btn-sm">Delete</button>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="col-md-6">
        <h3 class="border-bottom border-primary">Permissions</h3>
        <div class>
          <table class="table table-hover table-bordered">
            <tr>
              <th>Permission Name</th>
              <th>Guard</th>
              <th>Actions</th>
            </tr>
            <tr v-for="permission in permissions">
              <td>{{permission.name}}</td>
              <td>{{permission.guard_name}}</td>
              <td>
                <button class="btn btn-warning btn-sm">Edit</button>
                <button class="btn btn-danger btn-sm">Delete</button>
              </td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import PopModal from "../modals/popup-modal";
import InputModal from "../modals/input.vue";
export default {
  components: {
    PopModal,
    InputModal
  },
  data() {
    return {
      roles: [],
      permissions: [],
      data: {
        name: "",
        ids: []
      }
    };
  },
  created() {
    this.fetchRoles();
    this.fetchPermissions();
  },
  methods: {
    fetchRoles() {
      axios.get("/admin/fetch/roles").then(res => (this.roles = res.data));
    },
    fetchPermissions() {
      axios
        .get("/admin/fetch/permissions")
        .then(res => (this.permissions = res.data));
    },
    saveRole() {
      // axios.post("/admin/add-role", this.data).then(res => {
      //   console.log(res.data);
      // });
      console.log(this.data);
    },
    savePermission() {
      // axios.post("/admin/add-role", this.data).then(res => {
      //   console.log(res.data);
      // });
      console.log("Permission Saved");
    }
  }
};
</script>

Check photo attachment -

https://ibb.co/fp95cx4

https://ibb.co/CmJnf0v

Activity icon

Replied to Micro Services With Laravel

when ever you publish video on any platform about microservices. just send me tutorials link. :)

Apr
06
4 months ago
Activity icon

Replied to Micro Services With Laravel

I never take any course here. I just learn from books pdf, documentation, some youtube video and issue discussed with expert like you.

So i thing that.

Activity icon

Replied to Micro Services With Laravel

Money is not everything. Grow the community.

If you make videos on this topic and upload on udmey i will buy your course.

Activity icon

Replied to Micro Services With Laravel

Ya you are right bro. So i said to make tutorials on this topic because on YouTube there no related video are.

Activity icon

Replied to Micro Services With Laravel

Not just for speed i need to decide to separate some part of my app so whenever i need to to change that part my other app part work properly and many more thing in my mind

Activity icon

Replied to Micro Services With Laravel

Any Video tutorials on this particular topic?

Activity icon

Replied to Micro Services With Laravel

Can you create some videos on this topic.

Thanks in Advance...