Shiva

Shiva

Member Since 5 Years Ago

Experience Points
20,970
Total
Experience

4,030 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 5
20,970 XP
Oct
20
1 week ago
Activity icon

Started a new Conversation Getting My Modal To Have The Correct Product With Livewire

Is there a way to emit from the Livewire's component in my case that is Products.php to my blade component?

What I'm trying to do is create a page where when the user wants to delete a product a popup will show up and ask if you sure that you want to delete the product and if so then click the delete button.

The problem I'm having is that my modal is selecting the last record in the database, so when I delete a product it isn't deleting the product I wanted.

Here is my code.

This is my Products.php

<?php

namespace Modules\Products\Http\Livewire;

use Modules\Products\Models\Product;
use Livewire\Component;

class Products extends Component
{
    public $modal = false;

    protected $listeners = [
        'productDeleted' => 'deleteModal',
        'close' => 'close',
        'confirmDelete' => 'delete'
    ];

    public function render()
    {
        return view('products::livewire.products', [
            'products' => Product::all()
        ]);
    }

    public function deleteModal($id)
    {
    	$user = User::find($id);
        $this->modal = true;
    }

    public function close()
    {
        $this->modal = false;
    }
}

this is my products.blade.php

@foreach($products as $product)
    <button wire:click="$emit('productDeleted', {{ $product->id }})" class="bg-red-400 hover:bg-red-300 text-red-800 font-bold py-2 px-4 rounded inline-flex items-center">Delete</button>
    @if($modal)
        @include('products::livewire.deleteProductModal', ['product' => $product])
    @endif
@endforeach

and this is my deleteProductModal.blade.php

{{ $product->title}}
Oct
19
1 week ago
Activity icon

Started a new Conversation Changing The Logo For A Two Factor Auth In Jetstream

I'm trying to use jetstreams two factor authentication. What I would like is to change the logo that I get.

So I use the Twilio Auth 2-Factor Authentication app on my phone and when I scan the QR code in the profile section I get the Laravel's logo or no logo at all if I change my app name.

I've moved the twoFactorQrCodeUrl() to my User.php so that I could edit it, but I'm still struggling to get the logo I want to show up on my Twilio Auth 2-Factor Authentication app

Activity icon

Replied to Getting Value To Show Up Using Livewire

@sinnbeck - I'm sorry about that, I forgot to add my controller and my edit blade.

Oct
18
1 week ago
Activity icon

Started a new Conversation Getting Value To Show Up Using Livewire

I'm using laravel and livewire and I'm trying to create an edit page. What I'm trying to do is get the value to show up in the textbox. So for example my edit page has product info that I'm trying to edit, but my product name isn't displaying in the textbox.

Here is my code

My ProductsController

public function edit(Product $product)
{
    return view('products::edit', [
        'product' => $product
    ]);
}

My edit.blade.php

@livewire('edit-products', ['product' => $product])

My ProductEdit.php

<?php

namespace Modules\Products\Http\Livewire;

use App\Models\Product;
use Livewire\Component;

class ProductsEdit extends Component
{
    public $name;
    public $product;

    public function render()
    {
        return view('products::livewire.edit-products', [
            'name' => $this->product->name
        ]);
    }

    public function updateProduct()
    {
        dd($this->name);
    }
}

My edit-products.blade.php

<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
    <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
                    id="product_name"
                    type="text"
                    name="product_name"
                    value="{{ $product->name }}"
                    wire:model="name"
                >
</div>

<button wire:click="updateProduct" class="bg-green-400 hover:bg-green-300 text-green-800 font-bold py-2 px-4 rounded inline-flex items-center">Save</button>
Oct
12
2 weeks ago
Activity icon

Started a new Conversation Using A Modal To Delete A User

I'm trying to create a modal that when you click delete it will delete a record, but first I need to be able to have that modal pop up.

I know that the reason is because of this line $('#delete_{{ $user->id }}').click(function(){ but I'm not sure how to add the user id without having to add the <script>...</script> to the foreach loop

Or do I need to do that?

Here is my code

    <table class="min-w-full divide-y divide-gray-200">
        <thead>
            <tr>
                <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
                    Name
                </th>

                <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider text-right">
                    <a href="{{ route('users.create') }}" class="bg-green-400 hover:bg-green-300 text-green-800 font-bold py-2 px-4 rounded inline-flex items-center">Add User</a>
                </th>
            </tr>
        </thead>

        <tbody class="bg-white divide-y divide-gray-200">
            @foreach($users as $user)
                <tr>
                    <td class="px-6 py-4 whitespace-no-wrap">
                        <div class="flex items-center">
                            <div class="ml-4">
                                <div class="text-sm leading-5 font-medium text-gray-900">
                                    {{ $user->name }}
                                </div>

                                <div class="text-sm leading-5 text-gray-500">
                                    {{ $user->email }}
                                </div>
                            </div>
                        </div>
                    </td>

                    <td class="px-6 py-4 whitespace-no-wrap text-right text-sm leading-5 font-medium">
                        <button id="delete_{{ $user->id }}" class="bg-red-400 hover:bg-red-300 text-red-800 font-bold py-2 px-4 rounded inline-flex items-center">
                            Delete
                        </button>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>

    <div class="modal-display-none">
        <div class="fixed z-10 inset-0 overflow-y-auto">
            <div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
                <div class="fixed inset-0 transition-opacity">
                    <div class="absolute inset-0 bg-gray-500 opacity-75"></div>
                </div>

                <span class="hidden sm:inline-block sm:align-middle sm:h-screen"></span>&#8203;

                <div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full"
                     role="dialog"
                     aria-modal="true"
                     aria-labelledby="modal-headline">

                    <div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
                        <div class="sm:flex sm:items-start">
                            <div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
                                <svg class="h-6 w-6 text-red-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
                                </svg>
                            </div>

                            <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
                                <h3 class="text-lg leading-6 font-medium text-gray-900" id="modal-headline">
                                    Delete User
                                </h3>

                                <div class="mt-2">
                                    <p class="text-sm leading-5 text-gray-500">
                                        Are you sure you want to delete this user? <br>
                                        This action cannot be undone.
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
                        <span class="flex w-full rounded-md shadow-sm sm:ml-3 sm:w-auto">

                            <form action="{{ route('users.delete', ['user' => $user->id]) }}" method="POST">
                                @method('DELETE')
                                @csrf

                                <button type="button"
                                        class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 bg-red-600 text-base leading-6 font-medium text-white shadow-sm hover:bg-red-500 focus:outline-none focus:border-red-700 focus:shadow-outline-red transition ease-in-out duration-150 sm:text-sm sm:leading-5"
                                        id="confirm_delete"
                                >
                                Delete
                            </button>
                            </form>

                        </span>

                        <span class="mt-3 flex w-full rounded-md shadow-sm sm:mt-0 sm:w-auto">
                            <button type="button" id="close" class="inline-flex justify-center w-full rounded-md border border-gray-300 px-4 py-2 bg-white text-base leading-6 font-medium text-gray-700 shadow-sm hover:text-gray-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue transition ease-in-out duration-150 sm:text-sm sm:leading-5">
                                Cancel
                            </button>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <style>
        .modal-display-none{
            display: none;
        }

        .modal-display{
            display: block;
        }
    </style>

    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script>
        $(document).ready(function(){
            $('#delete_{{ $user->id }}').click(function(){
                console.log('delete button');
                $('.modal-display-none').removeClass('modal-display-none').addClass('modal-display');
            });

            $('#confirm_delete').click(function(){
                $('.modal-display').removeClass('modal-display').addClass('modal-display-none');
            });

            $('#close').click(function(){
                $('.modal-display').removeClass('modal-display').addClass('modal-display-none');
            });
        });
    </script>
Oct
05
3 weeks ago
Activity icon

Awarded Best Reply on Sorting An Array To Be Ascending Order

I managed to do it. This is the code I used

$sortedItems = $this->product->getCategoryCodes();
ksort($sortedItems, SORT_NATURAL);
Activity icon

Replied to Sorting An Array To Be Ascending Order

I managed to do it. This is the code I used

$sortedItems = $this->product->getCategoryCodes();
ksort($sortedItems, SORT_NATURAL);
Activity icon

Replied to Sorting An Array To Be Ascending Order

@sinnbeck - I get this error "Call to a member function sortBy() on array"

Oct
02
3 weeks ago
Activity icon

Started a new Conversation Sorting An Array To Be Ascending Order

I'm trying to sort my array in ascending order. My array is kind of working, what I mean by that is I'm getting

    P1
    P10
    P11
    P12
    P2
    P3
    P4
    P40
    P41
    P42
    P5

but what I would like is this

    P1
    P2
    P3
    P4
    P5
    P10
    P11
    P12
    P40
    P41
    P42

Here is my code

    $sortedItems = $this->product->getCategoryCodes();
    sort($sortedItems);

This is what I get when I echo out my $sortedItems

array:2 [
    "P1" => Modules\...\Product{
        -name: "Product 1"
        -description: "A description"
    }
    "P2" => Modules\...\Product{
        -name: "Product 2"
        -description: "A description 2"
    }
]
Sep
23
1 month ago
Activity icon

Started a new Conversation Deleting From A Json File

I have a json file that looks like this

    {
        "product_1": {
            "category_1": "Category 1",
            "category_2": "Category 2"
        },
    }

What I'm trying to do is when I delete a category I want to remove the "key":"value" from the json file.

Here is my code

    public function deleteCategory($product, $category)
    {
        $storage = storage_path("/products.json");
        $file = file_get_contents($storage);
        $json = json_decode($file);

        unset($json->$product->$category);

        file_put_contents($storage, json_encode($json, JSON_PRETTY_PRINT));

        return (array)$json;
    }

What happens is when I delete a category it doesn't remove it from the json.

And what I found strange was if I did this dd(file_put_contents($storage, json_encode($json, JSON_PRETTY_PRINT))) then it would work but if I only had file_put_contents($storage, json_encode($json, JSON_PRETTY_PRINT)) then it doesn't work. So I'm not sure where I'm going wrong.

Sep
21
1 month ago
Activity icon

Started a new Conversation Getting Errors When Running Npm Run Dev

When I run npm run dev in my server, I get a bunch of errors and then it says that the complete log can be found in .npm.

I checkout the log, but I'm still not sure as to why I'm getting errors. One of the reasons why I'm not sure as to what is going on is because if I run npm run dev on my local machine, it works fine.

error log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle @~predev: @
6 info lifecycle @~dev: @
7 verbose lifecycle @~dev: unsafe-perm in lifecycle true
8 verbose lifecycle @~dev: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:{{ path_to_file }}/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle @~dev: CWD: {{ path_to_file }}
10 silly lifecycle @~dev: Args: [ '-c', 'npm run development' ]
11 silly lifecycle @~dev: Returned: code: 1  signal: null
12 info lifecycle @~dev: Failed to exec dev script
13 verbose stack Error: @ dev: `npm run development`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid @
15 verbose cwd {{ path_to_file }}
16 verbose Linux 5.3.0-1032-azure
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
18 verbose node v12.18.2
19 verbose npm  v6.14.5
20 error code ELIFECYCLE
21 error errno 1
22 error @ dev: `npm run development`
22 error Exit status 1
23 error Failed at the @ dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

my package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "cross-env": "^7.0",
        "laravel-mix": "^5.0.1",
        "laravel-mix-merge-manifest": "^0.1.2"
    },
    "dependencies": {
        "algoliasearch": "^4.5.1",
        "express": "^4.17.1",
        "instantsearch.css": "^7.4.5",
        "vue-bootstrap-typeahead": "^0.2.6",
        "vue-instantsearch": "^3.2.0",
        "vue-router": "^3.4.3",
        "vue-server-renderer": "^2.6.12",
        "vue-simple-suggest": "^1.10.2",
        "vuetify": "^2.3.10",
        "webpack-merge": "^5.1.4"
    }
}
Activity icon

Started a new Conversation How To Get The Agolia Search To Only Display Courses That Belong To A User

I'm trying to create a search bar that uses laravel's scout and agolia. That search bar will allow the user to search for courses that they belong to, but at the moment they can see all courses and what I would like is to only display the courses that a logged in user has access to.

my Course.php model

	<?php

	namespace App;

	use Illuminate\Database\Eloquent\Model;
	use Laravel\Scout\Searchable;

	class Course extends Model
	{
		use Searchable;	

		public function searchableAs()
		{
			return "test_search";
		}

		public function toSearchableArray()
		{
			$array = [];
			$user = User::find(request()->user()->id);

			foreach($user->course as $course)
			{
				$array = [
					'id' => $course->id,
					'name' => $course->name
				];	
			}
			

			return $array
		}

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

My course.blade.php

	@extends('layouts.app')

	@section('content')
	    <div id="search">
	        <search></search>
	    </div>
	@endsection

	@push('js')
		<script type="text/javascript" src="{{mix('js/search.js')}}"></script>
	@endpush

My CourseSearch.vue

	<template>
	    <ais-instant-search :search-client="searchClient" index-name="test_search">
	        <ais-autocomplete>
	            <div slot-scope="{ currentRefinement, indices, refine }">
	                <input type="search" class="form-control" @input="refine($event.currentTarget.value)">
	                <ul v-if="currentRefinement" v-for="index in indices">
	                    <li v-for="hit in index.hits">
	                        <p>
	                            <ais-highlight attribute="name" :hit="hit"/>
	                        </p>
	                    </li>
	                </ul>
	            </div>
	        </ais-autocomplete>
	    </ais-instant-search>
	</template>

	<script>
	import algoliasearch from 'algoliasearch/lite';

	export default {
	    data() {
	        return {
	            searchClient: algoliasearch(
	                'my_algolia_id',
	                'my_algolia_key'
	            ),
	        }
	    },
	    methods: {

	    },
	    mounted() {
	       
	    }
	}
	</script>
Sep
14
1 month ago
Activity icon

Started a new Conversation How To Type And Filter In A Dropdown Select In Vue

I have a dropdown that has a list of categories. What I would like is to be able type in the dropdown and filter my dropdown with what I've typed.

Here is my code

<template>
    <transition name="modal-fade">
        <div>
            <div class="modal-backdrop show"></div>
            <div class="modal" style="display: inline;">
                <div class="modal-dialog modal-dialog-scrollable" role="document" style="width: 680px; max-width: 680px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">{{product.name}}</h5>
                            <button type="button" class="close" @click="close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm">
                                <thead>
	                                <tr>
	                                    <th>Name</th>
	                                    <th>Remove</th>
	                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="cat in addedCat">
                                    <td>[{{ cat.id }}] {{ cat.name }}</td>
                                    <td><button @click="removeCat(cat)" class="btn btn-sm btn-danger">Remove</button></td>
                                </tr>
                                <tr>
                                    <select class="form-control">
                                        <option value=""><input type="text"></option>
                                        <option v-for="option in options" :value="option.id">{{ option.text }}</option>
                                    </select>
                                </tbody>
                            </table>


                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" @click="close">Close</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </transition>
</template>

<script>
    export default {
        props: ['user', 'products', 'bus'],
        data() {
            return {
                addedCat: [],
                options: []
            }
        },
        mounted() {
            axios.get('/admin/product/'+this.product.id+'/categories').then((response) => {
                this.addedCat = response.data.categories;
            });

			this.getCategories();
        },
        computed: {

        },
        methods: {
            getCategories(){
                let filCat = this.categories.filter(c => {
                    return this.addedCat.find(ac => ac.id === c.id) == null;
                })

                this.options.push({id: 0, text: "Please select one"});

                filCat.forEach(c => {
                    this.options.push({
                        id: c.id,
                        text: c.name
                    });
                });
            },
        }
    }
</script>
Sep
03
1 month ago
Activity icon

Replied to Deleting A File

@sinnbeck - thank you so much that was it

Activity icon

Started a new Conversation Deleting A File

I've created a command that will delete some files from my storage directory, but when I run it, it doesn't delete the files and there is no error in my log file.

Here is my code

  public function handle()
    {
        $storage = storage_path('avatars/profile');

        $files = scandir($storage);

        foreach($files as $file)
        {
            if($file == ".") continue;
            if($file == "..") continue;
            File::delete($file);
        }
    }
Aug
31
1 month ago
Activity icon

Started a new Conversation How To Include A Folder From The Resources Folder

I'm trying to get a video from my videos folder that is in my resources folder. When I try to do this

@include('resources::videos.video1.mp4')

I get this error

No hint path defined for [resources].

Here is my full code

<div class="content">
    <div class="row">
        <div class="col-lg-2">
            <ul class="nav nav-tabs flex-column" id="myTab" role="tablist">
                <li class="nav-item" role="presentation">
                    <a class="nav-link active" id="video1-tab" data-toggle="tab" href="#video1" role="tab" aria-controls="video1" aria-selected="true">video1</a>
                </li>
                <li class="nav-item" role="presentation">
                    <a class="nav-link" id="video2-tab" data-toggle="tab" href="#video2" role="tab" aria-controls="video2" aria-selected="false">video2</a>
                </li>
            </ul>
        </div>

        <div class="col-lg-10">
            <div class="tab-content" id="myTabContent">
                <div class="tab-pane fade show active" id="video1" role="tabpanel" aria-labelledby="video1-tab">
                    @include('resources::videos.video1.mp4')
                </div>
                <div class="tab-pane fade" id="video2" role="tabpanel" aria-labelledby="video2-tab">video2</div>
            </div>
        </div>
    </div>
</div>
Aug
20
2 months ago
Activity icon

Replied to Cannot Update My Json File Index Keys

I tried that but my keys never changed

Activity icon

Started a new Conversation Cannot Update My Json File Index Keys

I'm trying to run a artisan command but I'm having a bit of a problem trying to update my json file in my json file it looks like this

{
    "CL001": {
        "client_name": "Client 1",
        "client_email": "[email protected]",
    },
    "CL002": {
      "client_name": "Client 2",
      "client_email": "[email protected]",
    }
}

What I need to do is a bulk change on my client codes so for example CL001 needs to be PR001.

I've managed to isolate the codes but I'm having a bit of trouble trying to push the codes up so that they can change.

Here is my codes

$old_code = "CL001";
$new_code = "PR001";


$json = (array)json_decode(file_get_contents(storage_path('/Clients/clients.json')));

foreach($json as $key => $value)
{
  if(stripos($key, $old_code) !== false)
  {
     $newClientCode = str_replace($old_code, $new_code, $key);
  }
}

and that is where I get stuck. I'm not sure how to now go and update my json file with the new codes

Jul
30
2 months ago
Activity icon

Replied to How To Get Vue Router To Go To Another Page

@maverickchan - cool I will look into that, but will that solve my problem because even if I change the path for example to my home page it still doesn't change

Activity icon

Replied to How To Get Vue Router To Go To Another Page

@maverickchan - but wouldn't it be called when I do this import Users from "../users/Users"; in my permissions.js

Activity icon

Replied to How To Get Vue Router To Go To Another Page

@topvillas - nope I don't get any errors

Activity icon

Started a new Conversation How To Get Vue Router To Go To Another Page

I have a laravel vue app and I'm trying to create a roles and permissions page that links to the users page.

The problem I'm having is that, when you're on the permissions page and you open up the users panel and you select a user and you decide you need to change their details and you click on their edit button and that should take you to the users page.

So far I've only managed to get the url to change but the page stays on the permissions page.

My permissions.vue

<template>
  <div>
    <h3>Users</h3>

    <div>
      <table>
        <thead>
          <tr>
            <th>Permission Name</th>
            <th style="width:240px;"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="permission in permissions">
            <td>{{permission.name}}</td>
            <td style="text-align: right;">
              <button class="btn btn-sm btn-outline-info" @click="users(permission)">
                Users
              </button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
  export default {
    props: ['emit', 'roles'],
    data() {
      return {

      }
    },
    computed: {

    },
    mounted() {

    },
    methods: {
      users(permission) {
        this.emit.$emit('edit-users', { permission: permission });
      }
    }
  }
</script>

this.emit.$emit('edit-users', { permission: permission }); then opens up the users panel on the permission page

<template>
  <div>
    <h3>Users in <strong>{{permission.name}}</strong></h3>

    <div>
      <table>
        <thead>
          <tr>
            <th>User</th>
            <th style="width:120px;"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="user in users">
            <td>{{user.name}}</td>
            <td style="text-align: right;">
              <button class="btn btn-sm btn-outline-info" @click="edit(user)">
                Edit
              </button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
  export default {
    props: ['emit', 'role'],
    data() {
      return {
        users: []
      }
    },
    computed: {

    },
    mounted() {
      this.getUsers();
    },
    watch: {

    },
    methods: {
      getUsers() {
        axios.get('/admin/permissions/'+this.permission.name+'/users').then(response => {
          this.users = response.data.users;
        });
      },
      edit(user) {
        this.$router.push({name: 'Users', params: {id: user.id}});
      }
    }
  }
</script>

in my permissions.js I have

import VueRouter from 'vue-router';
Vue.use(VueRouter);

import Users from "../users/Users";

const router = new VueRouter({
  mode: 'history',
  routes: [
    {
      path: '/admin/users/:id',
      name: 'Users',
      component: Users
    }
  ]
})

if (document.getElementById('permissions')) {
  const app = new Vue({
    el: "#permissions",
    router,
    data() {
      return {
        emit: new Vue(),
      }
    },
    methods: {

    },
    mounted() {

    }
  });
}
Jul
01
3 months ago
Activity icon

Replied to Schema::hasColumn Not Working Correctly

@deepu07 - I'm using DB::connection('second')->table('products)->where('category_id', $category_id);

Activity icon

Started a new Conversation Schema::hasColumn Not Working Correctly

I'm trying to find out if a column exists in a table. I tried doing this

if(Schema::hasColumn('products', 'category_id'))
{
    dd('has category_id');
}else{
    dd('doesnt have category_id');
}

the reason why I say it isn't working is because if I check my network tab I see that doesnt have category_id printed out and if I do check my products table then the category_id is there. So what is supposed to happen is that if category_id does exist then has category_id is supposed to be printed out.

Jun
30
3 months ago
Activity icon

Started a new Conversation ErrorException : Illegal Offset Type

I have a csv that looks like this

product,title,category,price\n
PR001,"Product Title 1","Category 1", 123\n
PR002,"Product Title 2","Category 2", 123\n
PR003,"Product Title 3","Category 3", 123\n
PR004,"Product Title 4","Category 4", 123\n
PR005,"Product Title 5","Category 5", 123\n

What I would like to do is get an array that looks like this

array:5 [
  "PR001" => "123"
  "PR002" => "123"
  "PR003" => "123"
  "PR004" => "123"
  "PR005" => "123"
]

When I run my code I get this error

 ErrorException  : Illegal offset type

Here is my code


$users = User::all();

$productArr = [];

foreach($users as $user)
{
	$csv = $user->getCsv();

	$lines = explode(PHP_EOL, $csv);
    $csvArray = [];

    foreach($lines as $line)
    {
        $csvArray[] = str_getcsv($line);
    }

    $keys = array_shift($csvArray);

    $result = array_combine($keys, array_map(null, ...$csvArray));

    $productArr[$result['product']] = $result['price'];
}

dd($role);