vajid

vajid

Member Since 1 Year Ago

Software Engineer at India

Experience Points 10,950
Experience Level 3

4,050 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 16
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

07 Feb
6 months ago

vajid started a new conversation Check If Relation Exists On Given Column Name

i am working on a product which records changes made to given model. So far I am able to get new as well as old data when user is updating the model.

now I would like to check if changed column holds ID of another table, if yes get name attribute of that relation.

E.g manager_id, etc if manager_id column is updated get his/her name before and after update instead of saving new and old ID

if (count($model->getDirty()) == 0) {
        return;
    }

    $remark = auth()->user()->first_name .' '. auth()->user()->last_name . ' made following changes [ ';
    $changes = [];
    foreach ($model->getDirty() as $key => $value) {
        if (is_numeric($value) && strlen($value) <= 2) {
            //changed columns holds id of another table

        } else {
            $changes[] = ucfirst(str_replace('_',' ', $key)) . ' changed to '. $value . ' from '.$model->getOriginal($key);
        }
    }

    $remark .= implode(', ', $changes). ' ] on '. date('d-m-Y h:i:s A');
    dump($remark);

sample output

Admin made following changes [ First name changed to New Name from Admin, Last name changed to last Name from Admin ] on 07-02-2019 03:25:59 PM

17 Jan
7 months ago

vajid left a reply on Getting A Variable To Be Passed To My Store Function

@nikki your error is about store function not receiving $image as an agrument, you have to pass it from where you are calling this store function

16 Jan
7 months ago

vajid left a reply on Getting A Variable To Be Passed To My Store Function

//make this change from where you are calling this route

//also you are not using $image, why not remove it or make it optional?

{{route('name_of_store_route',['image' => 'my_image'])}}
15 Jan
7 months ago

vajid left a reply on How To Unset Appended Data From Model?

$model->name = 'dummy name';
$freshModel = $model->fresh();
$model->name = $freshModel->name;

vajid left a reply on Add Multiple Variable To View

@sarzali

Considering above solution didnt worked, your view might be rendering from different method and you are passing data from different method.

make sure you are editing correct method by doing dd('here') before returning view

14 Jan
7 months ago

vajid left a reply on Mail Queue Status

@yassineqoraiche Have a look at Laravel Horizon package

https://laravel.com/docs/5.7/horizon

10 Jan
7 months ago

vajid left a reply on Passing Value

public function form(Request $request)
    {

        $detail_id = $request->id;

        $JobDetail = JobDetailModel::findOrFail($detail_id);     

        return view('form', compact('JobDetail'));
    }

<input required type="hidden" class="form-control" id="nama" placeholder="" value="" name="{{ $JobDetail->id }}">
09 Jan
7 months ago

vajid left a reply on Layout File In A Subdirectory?

@chrisf79

I am guessing you want to fill some footer content from layout blade

in your footer.blade.php

... some html

@stack('footer-content')
...some html

... in layout.blade.php

@include('footer.blade.php')
@push('footer-content')
FOOTER CONTENT FROM LAYOUT
@endpush

This way you can fill content in footer from layout file, from other location( other layout file) just push content in footer-content section

08 Jan
7 months ago

vajid left a reply on How To Add A JS Variable Into A Hidden Form Value

@daugaard47

place this code inside update function

//inside update at the end
totalDonation.text((checkbox.checked ? f(goal) + f(charge) : f(goal)).toFixed(2));
var xyz = $('#total-box').text();
$("#xyz").val(xyz);
var hiddeninput = $("#xyz").val();

vajid left a reply on Help Needed To Convert Update Query To UpdateOrCreate

@ssquare for update part send id in hidden field or in parameter and in controller check if id is present

$id = request()->student_id;

Student::where('name_last', $student['name_last'])
->when($id, function($q){
    $q->where('id', $id);
})
->first();

Student::updateOrCreate(
['id'=>$id ]
....

vajid left a reply on Help Needed To Convert Update Query To UpdateOrCreate

@ssquare why not just use phone and email for selecting student both are unique by the way

vajid left a reply on How To Add A JS Variable Into A Hidden Form Value

@daugaard47 with ID you can use it number of times too, it just makes element selection more readable and easy to figure whats happening.

Have tested it on your codepen it was working E.g 120 without gift and with gift checkbox checked 123.89

vajid left a reply on Help Needed To Convert Update Query To UpdateOrCreate

@ssquare you are almost there

just change

Student::updateOrCreate(
        ['name_first' => $student['name_first], 'name_last' => $student['name_last]],
        $student //assuming it is key value pair, where key is db column name
 );

vajid left a reply on How To Add A JS Variable Into A Hidden Form Value

@daugaard47 @cronix totally agreed

//totalDonation.text((checkbox.checked ? f(goal) + f(charge) : f(goal)).toFixed(2));
$('#xyz').val((checkbox.checked ? f(goal) + f(charge) : f(goal)).toFixed(2));
07 Jan
7 months ago

vajid left a reply on How To Add A JS Variable Into A Hidden Form Value

@daugaard47 as you have multiple class with name total-box you have to specify jquery which index to look at for price or it will check for last occurence

$('.total-box > span').eq(0).text();

vajid left a reply on Can We Pass Null To Laravel Resource

@skycoder do a auth check

$data = [
    'appName' => config('app.name'),
    'locale' => app()->getLocale(),
];

if (auth()->check()) {
    if($this->hasRole('basic')) {
        $data['user'] = $this->only(['username', 'fullname', 'avatar']);
    }
} else {
$data['user'] = null;
}


return $data;

vajid left a reply on Timeout Queue Process

@labib47

php artisan queue:listen --timeout=300

vajid left a reply on How To Add A JS Variable Into A Hidden Form Value

since you are using JQuery why not try like this

var xyz = $('.total-box > span').text();
console.log('xyz', xyz);
$('#xyz').val(xyz);

vajid left a reply on The Images Failed To Upload.

if($request->hasFile('images')){

//here you have to save path not the file itself
Student::create([
        'student_name'=> $request->get('student_name'),
        'age'=>$request->get('age'),
        'email'=>$request->get('email'),
        'parent_name'=>$request->get('parent_name'),
        'phone'=>$request->get('phone'),
        'images'=>$path// or path to noimage.jpg
    ]);

vajid left a reply on Import Mysql File Into Mysql Linux

@davy_yg you didn't mention about vmware in the first place.

I haven't worked much on vmware sharing folder, but when you have the .sql file in your linux above step will work.

vajid left a reply on Import Mysql File Into Mysql Linux

yes you can do it.

step 1. login in mysql cli
step 2. create database
step 3. use new_db_name
step 4. source location_of_mysql_file.sql

vajid left a reply on Building My First PWA, Running Into Issues!

@thebigk

  1. Yes workbox is a cli tool by google to create SW and for offline capability
  2. PWA need https, so it wont run on your real advice from your local server without port forwarding and you can use any port, you just have to add rule

localhost:8080 localhost:8080

for more refer step 2 https://medium.com/progressive-web-apps/react-progressive-web-apps-part-1-1cf381421672

vajid left a reply on Get Data From AJAX Request, Multiple Array

@andreasnr do a dd($request->all()) and check the response in network tab

06 Jan
7 months ago

vajid left a reply on Building My First PWA, Running Into Issues!

Answer 1. You can use workbox cli to generate your service worker file, if you need custom code in your service worker you can inject it too and workbox will generate sw code for you.

Answer 2. workbox will handle dynamic assets caching by default so you dont have worry about it.

Answer 3. this is working for me, navigate to more tool > remote device > select device and rule

04 Jan
7 months ago

vajid left a reply on Push To Collection Key


foreach($array as $data) {

if (isset($data['numbers'])) {
        array_push($data['numbers'], $new_number);
    }
}


vajid left a reply on Get Data From AJAX Request, Multiple Array

//controller
$ids  = request()->IDs;
$times = request()->times;
$names = request()->name;


return Response::json(['message'=>'gespeichert','data'=>$name],200);

//IDs, times, name are key, given in ajax data property

03 Jan
7 months ago

vajid left a reply on Eager Loading With Where Clause Not Working As Expected

@makapaka

try this

$league = League::with('team')->whereHas('team',  function($q)  {
            $q->where('name', 'team_name');//query on team model
        })->first();

vajid left a reply on My Query And Conversion To Eloquent

@foreach($leeds as $leed_grp)
    <div>
        <span>{{ count($leed_grp) }}</span>
        <span>{{ $leed_grp[0]->created_at }}</span>
    </div>
    @endforeach

vajid left a reply on My Query And Conversion To Eloquent

Contact::select(['id','created_at'])
->get()
->groupBy(function($date) {
      return \Carbon\Carbon::parse($date->created_at)->format('Y-m-d');
});
02 Jan
7 months ago

vajid left a reply on Permission Denied For Laravel Storage Logs

sudo chmod 777 -R /var/www/html/storage/

27 Dec
7 months ago

vajid left a reply on Users That Can Create Another Users And Restrict Some Functionality On Website

What you need is ACL, laravel has ACL packages.

you dont need another model, just set a column in users table which holds type of user like admin,creator and normal_user. and based on this column value you can perform your logic and restricting users.

also check LARAVEL GATE AND POLICY it might meet your requirement

vajid left a reply on How Do You Register Custom Methods Like Those Within Application.php In Laravel

what you can do is make a separate file with all of your method and load it with composer

//composer.json

"autoload": {
        
        ....,
        "files": [
            "app/path_to_your_file1.php",
        "app/path_to_your_file2.php",
        ]
    },
//your_file.php
<?php

function sayHI(){
echo 'HI';
}

now sayHi() is available anywhere in your application

and do composer dump every time you add or remove entries in files array

vajid left a reply on Want To Create PDF File And Send Email In My Laravel 5.3

@towhid I have used snappy pdf for creating pdf at run time and sending it via email.

create pdf and store it in a variable and attach it to mail.

snappy pdf has function like to stream, output and download. output function is what you need.

vajid left a reply on Send Emails Occasionally And Delete Users Every X Months

scheduler is best for this kind of work

vajid left a reply on Call To A Member Function Count() On Null

$data = UserWebModel::where('email', $request->email)->first();

will return object not a collection, so you cant use count instead use

get() or firstorFail()

if you want to use first,

 elseif($data){
}

and as the error says, $data in null,so

if(!$data){
enter valid email address
}

vajid left a reply on Hide Flash Message

do you have alert class inside flash blade?

vajid left a reply on AJAX Passed Id Same Even If It Is Manually Changed

@pickab00 using data makes sense once you done with testing

vajid left a reply on AJAX Passed Id Same Even If It Is Manually Changed

you cant simply change the value of attribute by inspecting and editing

use

var product_id = $(this).attr('data-id');

$.fn.attr stores the information directly on the element in attributes which are publicly visible upon inspection, and also which are available from the element's native API. http://api.jquery.com/attr/

$.fn.data stores the information in a ridiculously obscure place. It is located in a closed over local variable called data_user which is an instance of a locally defined function Data. This variable is not accessible from outside of jQuery directly. http://api.jquery.com/data/

vajid left a reply on Task App: Check If All Subtasks Are Completed


if($parentTask->subTasks()->where('is_active',1)->count() == 0){
    $parentTask->update(['is_active'=>0]);
}

vajid left a reply on Different Access

@douglasakula lets say your admin menu has something url payment/setting

you are not showing this url in your view, but lets assume by any means normal user enters this url if you are not protecting it via middleware or using guard on setting page to hide the details, all of your important info will be visible.

You can try it where you have implemented like this in your project

https://laravel.com/docs/5.7/authorization#writing-gates

sorry by guard I meant Gate

vajid left a reply on How To Use Localtime In Laravel Server Based On User Ip Timezone

I would prefer saving in database with server timezone and when user is trying to view something, I would convert saved timezone to user timezone with Accessor.

vajid left a reply on Using Where Clause For Two Tables

:) glad to hear it.

vajid left a reply on Different Access

@douglasakula what if user enter url manually in address box?

@davy_yg with guard you can control which part of your blade or code user can view or execute

to block access to certain url for this you have middleware

vajid left a reply on Only Show Parent Tasks Or Single Tasks In Tasks List

Scope will be good practice.

vajid left a reply on Trouble With "Add To Cart"

@pickab00 you are good to go make sure

var url = "/addToCart/" + product_id + '/' + gem;

is in web middleware

Route::post('addToCart/{product}/{gem}', ......)->middleware('web');
or if you have applied some where else

vajid left a reply on Trouble With "Add To Cart"

@pickab00

wrap it inside a span or div

or

<ul>
    @foreach($menuCategory as $menuCategories)
    <li>
        {{$menuCategories->name}}
        <ul>
            @foreach($menuCategories->menuitems as $menuItems)
            <li>{{$menuItems->item_name}}</li>
            
            <input type="number" class="qty" data-qty="{{$menuItems->price}}" data-btn="{{$menuItems->id}}">
            <button data-qty="{{$menuItems->price}}" data-id="{{$menuItems->id}}" class="addCart">Add To Cart</button>
            @endforeach
        </ul>
    </li>
    @endforeach
</ul>
$('.addCart').click(function(){
    $parent = $(this).parent();
    $input = $parent.find("[data-btn='"+$(this).data('id')+"']");
    alert($input.val());
});

I think wrapping will be make your easier to read and maintain at later stage

vajid left a reply on Using Where Clause For Two Tables

public function sale()
    {
        return $this->hasMany('App\SaleDetail', 'ticket_id');
    }

public function repair()
    {
        return $this->hasMany('App\RepairDetail', 'ticket_id');
    }

$ticket = Ticket::whereHas('sale', function($query){
    $query->where('is_custom', $data['sale_custom']);
})
->orWhereHas('repair', function($query){
    $query->where('is_custom', $data['sale_custom']);
})->get();

vajid left a reply on Trouble With "Add To Cart"

@pickab00 you are safe as long as csrf is added and you route is in web middleware

//its working for me, I copied your implementation
<ul>
<li>
    <ul>
        @for($i = 0; $i< 5; $i++)
        <li>
            <input type="text" class="qty" value="{{$i}}"> <br>
            <button class="addCart">ADD</button>
        </li>
        @endfor
    </ul>
</li>
</ul>
$('.addCart').on('click', function(){
    alert($(this).closest('li').find('.qty').val())
});