Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    robertlook
    @robertlook

    Simply laravel middleware filter all the HTTP requests in laravel based on projects. For example when the user is doing any request that time middleware check user is logged in or not and redirect accordingly. Any user is not logged in but he wants to access the dashboard or other things in projects that time middleware filter requests redirect to the user.

    This example of active or inactive users access laravel 8 app or not. So, add this middleware with routes to restrict logged user to access routes, if he/she is inactive by admin.How To Use/Create Middleware Laravel 8 Example

    robertlook
    @robertlook

    I explained simply step by step laravel 8 Cron job scheduler. This tutorial will give you a simple example of how to create a Cron job in your project. This article goes into detail on how to make a Cron job at this time. So, let's follow a few steps to create an example of Cron job schedule laravel 8.

    Any time Why we have to use Cron's job? and what is the benefit to use Cron jobs in your project and what is a Cron job and how to set up a Cron job in laravel 8?, If you have this question then I will explain why. Many times we need to send notifications or send emails automatically to users to update property or products. So this time, you can define Cron job scheduler syntax some basic logic for each day, hours, etc can run and send an email notification. We have covered Cron job scheduler syntax. Cron Job Scheduler | cron job syntax | How to setup cron job in laravel

    Clay McLeod
    @claymcleod
    I'm writing a test to check authorization for a resource controller, and I'm trying to use a Mockery::spy to ensure the correct policy method is being called. Does anyone have any experience doing that? This is currently what I'm trying, though that is failing.
    $this->instance(WidgetPolicy::class, Mockery::spy(WidgetPolicy::class, function ($mock) {
        $this->actingAs($new_user)
            ->get('/api/widgets')
            ->assertStatus(Response::HTTP_FORBIDDEN);
        $mock->shouldHaveReceived()->viewAny();
    }));
    FWIW, the error I'm getting:
    Mockery\Exception\InvalidCountException : Method viewAny(<Any Arguments>) from Mockery_2_App_Policies_WidgetPolicy should be called at least 1 times but called 0 times.
    robertlook
    @robertlook
    Almost require to create an active inactive functionality in laravel. it might be required for user status, product status, category status, etc. we have always enabled or disabled, active and inactive, etc. you can do it this toggle status active inactive PHP example this time. Active Inactive Status Using Toggle Button/Slide laravel 8
    xlcrr
    @xlcrr
    Hey guys. Can anyone suggest how to run a node + npm script on laravel backend? I want to grab some data, run npm script on it and save results to a table
    Ben Johnson
    @cbj4074
    @xlcrr Hey! You should be able to do that just like you would run any other program with Laravel, e.g., using the Symfony\Component\Process\Process component.
    The documentation is good and straightforward: https://symfony.com/doc/current/components/process.html
    This approach should work regardless of how the node command and its arguments need to be strucutred.
    (i.e., whether you need to stream input from a file or simply pass the input source as a filepath argument to the node executable)
    pikonetto
    @pikonetto
    Hey! I would like to use Socialite package for SAML2 auth, but I don’t understand how I can do it, can anyone help me?
    Zachary Smith
    @zachisit

    I can't figure this out, and would love someone smarter than me to tell me what I'm missing.
    The following code is ran on an array of dates:
    $diff = $firstAvailable->diffInMinutes($end);

    Iterating over these results, the first day (the 'today') returns incorrect minutes, but every day after seems to be correct.

    [2020-10-20 16:58:11] local.INFO: --- looking at today hours
    [2020-10-20 16:58:11] local.INFO: end
    [2020-10-20 16:58:11] local.INFO: 2020-10-20 23:00:00
    [2020-10-20 16:58:11] local.INFO: first avail
    [2020-10-20 16:58:11] local.INFO: 2020-10-20 14:00:00
    [2020-10-20 16:58:11] local.INFO: diff in mins
    [2020-10-20 16:58:11] local.INFO: 300
    [2020-10-20 16:58:11] local.INFO: ---
    [2020-10-20 16:58:11] local.INFO: end
    [2020-10-20 16:58:11] local.INFO: 2020-10-21 23:00:00
    [2020-10-20 16:58:11] local.INFO: first avail
    [2020-10-20 16:58:11] local.INFO: 2020-10-21 12:00:00
    [2020-10-20 16:58:11] local.INFO: diff in mins
    [2020-10-20 16:58:11] local.INFO: 660
    [2020-10-20 16:58:11] local.INFO: ---
    [2020-10-20 16:58:11] local.INFO: end
    [2020-10-20 16:58:11] local.INFO: 2020-10-22 23:00:00
    [2020-10-20 16:58:11] local.INFO: first avail
    [2020-10-20 16:58:11] local.INFO: 2020-10-22 12:00:00
    [2020-10-20 16:58:11] local.INFO: diff in mins
    [2020-10-20 16:58:11] local.INFO: 660
    [2020-10-20 16:58:11] local.INFO: ---
    [2020-10-20 16:58:11] local.INFO: end
    [2020-10-20 16:58:11] local.INFO: 2020-10-24 01:00:00
    [2020-10-20 16:58:11] local.INFO: first avail
    [2020-10-20 16:58:11] local.INFO: 2020-10-23 12:00:00
    [2020-10-20 16:58:11] local.INFO: diff in mins
    [2020-10-20 16:58:11] local.INFO: 780
    Ben Johnson
    @cbj4074
    @robertlook Why regurgitate all these random links? I'm not sure anyone finds them helpful.
    edvordo
    @edvordo
    I was giving him the silent treatment in hopes he'd stop eventually.
    Ben Johnson
    @cbj4074
    :D Guessing it's a bot of some kind... probably his first script and he's quite proud of it.
    Jo-Dev-1337
    @Jo-Dev-1337

    I've developed a PHP package and i want to implement WEB GUI CRUD on it

    The Question:

    How i can i save the objects in the database
    I know that I can make a model for each class in the pakage but how i can link the model with the real class

    Suppose i have class Project and have onToMany relation with Statement

    How i can link between Project Class and Project Model. I want to use Project model just to save the input (content of project class) and build project class each time using project model.

    I Don't know if I explained the problem well but this is the conclusion:

    • I've developed PHP package and I want to use it in Laravel web app.
    • I want to save the objects in database so i will use Models.
    • how i Can use the models just for save the inputs, so by that if i have project class in the package i will create project model in the Laravel but i want to build Project class from Project model.
    Andrius Solopovas
    @asolopovas
    Hi Guys, does anyone know why when I do the following cache()->rememberForever('globals', fn() => json_encode(['foo' => 'bar'])); the value stored in cache is actually "s:13:\"{\"foo\":\"bar\"}\";" rather than "{\"foo\":\"bar\"}"? Is there a way I can store string without php serialization?
    Tinsh
    @kilofox
    The cache just stored data as STRING and the data you provided is also STRING.
    The STRING will be serialized, but it’s not PHP SERIALIZATION.
    Andrius Solopovas
    @asolopovas
    If I store it via redis-cli it does not get serialized
    but If store it with laravel it is serialized
    the question is how to avoid that?
    Tinsh
    @kilofox
    You set a cache using Laravel, so you should get the cache through Laravel, too.
    Andrius Solopovas
    @asolopovas
    @kilofox why?
    what if I use docker with redis, backend and front end containers and I want to share data between frontend application and backend
    Tinsh
    @kilofox
    Make a Redis instance to store your data.
    Andrius Solopovas
    @asolopovas
    @kilofox oh thank you that is what I haven't thought about. You helped me big time
    Denis Kovalev
    @deniskv
    Hello all! I'm confused a little by laraval front end part. I have fresh repo of laravel 8+ with bootstrap 4 and trying to understand next thing. When I building frontend with 'npm run production', I have app.js with more than 200kb (and it is minified). Ok, digging deaper and in resource folder I founded next: app.js requres bootstrap.js, bootstrap.js reuires axios and jquery. But when I'm trying to call jquery in view (jQuery(document) ... etc) I getting 'jQuery is not defined' in browser's console.
    Can someone explain to me what the problem is? And why the file weighs 200kb. What does this file consist of then?
    Andrius Solopovas
    @asolopovas
    @kilofox thanks to you my request to front end now reduced from 89 - 110 ms to 30ms
    Tinsh
    @kilofox
    Congratulations.
    Ali Shikhiyev
    @Alionides

    I'm trying to display all products from a category and it's all sub-categories

    Here's my categories table structure :
    id parent_id name
    1 NULL Vehicles
    2 1 Cars
    3 2 Motorcycles

    but i only get parent and its sub data. i want to get parent sub and subsub data.

    here is my category model

    public function subproducts()
    {
    return $this->hasManyThrough(Product::class, self::class, 'parent_id', 'category_id');
    }

    public function products() {
    return $this->hasMany(Product::class);
    }

    }

    here is my product

    public function categories() { return $this->belongsTo(Category::class, 'category_id'); }

    and this is the controller

    $category = Category::with(['products', 'subproducts'])->where('slug', $slug)->first();
    $allProducts = $category->products->merge($category->subproducts);

    dd($allProducts);

    Tinsh
    @kilofox
    I think $category->subCategories is needed.
    Ali Shikhiyev
    @Alionides
    I think $category->subCategories is needed.
    how?
    public function subcategory(){
        return $this->hasMany('App\Category', 'parent_id');
    
    }
    i had subcategory but i want to fetch products by category id or slug
    Tinsh
    @kilofox
    $category->subproducts doesn’t return the expected result?
    Ali Shikhiyev
    @Alionides

    $category->subproducts doesn’t return the expected result?

    it returns only parent and sub category products not sub subcategory products. it returns only 2 level but i want 3 level

    Tinsh
    @kilofox
    Maybe you have to loop the subcategories.
    xlcrr
    @xlcrr
    Anyone looking to help an open source project ? For the last few years, I have been empowering people to map litter. https://github.com/OpenLitterMap/openlittermap-web is now open source