mdobrenko

mdobrenko

Member Since 4 Years Ago

Chicago

Experience Points
11,010
Total
Experience

3,990 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
118
Lessons
Completed
Best Reply Awards
0
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.

Level 3
11,010 XP
15 Jun
1 year ago

mdobrenko left a reply on Cookie::queue Not Attaching To Response

For anyone else that runs into this problem: It looks like this middleware is only included for the 'web' group. I was making API calls, and so the queue method was not available.

14 Jun
1 year ago

mdobrenko started a new conversation Cookie::queue Not Attaching To Response

Looking at the Laravel documentation, it appears you can attach a cookie to your next outgoing response by utilizing the Cookie::queue method. However, after trying to do so, it looks like the cookies are not being passed back:

Cookie::queue('client_cookie', 'test', 1000);

I have tried variations where you pass in a Cookie::make(), Cookie::Forever(), but none of these work.

However, simply doing the following appears to return a cookie:

return response('success', 200)->withCookie(Cookie::make('client_cookie', 'Testing', 1000));

Am I doing something incorrectly? I pulled in the Cookie class by using 'use Cookie;'

Is there some additional package I need to pull in?

12 Jun
1 year ago

mdobrenko started a new conversation Deploying Laravel Echo + Websockets

Currently, I have a two branches on my live server: development and production. Pushing my local development to the live development branch works fine, and the websocket configuration works out. However, merging development with production creates problems because the two share the same server; running two instances of laravel-echo-server is not allowed on the same port. I could add bootstrap.js to my .gitignore, but then if I made any changes to the bootstrap.js file, development and production would not change accordingly.

Any advice on a good implementation for this? Is there a way to utilize environmental variables here? (I would assume that's not a good idea if possible, for security purposes).

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.$ = window.jQuery = require('jquery');
    require('bootstrap-sass');
} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Next we will register the CSRF Token as a common header with Axios so that
 * all outgoing HTTP requests automatically have it attached. This is just
 * a simple convenience so we don't have to attach every token manually.
 */

let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

import Echo from 'laravel-echo'

window.io = require('socket.io-client');

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001',
});
03 Jun
1 year ago

mdobrenko started a new conversation Laravel Echo + SocketIO + Redis

I managed to get Laravel Echo up and running, but cannot figure out how to emit events from the client side (as opposed to simply listening). I am using the following:

Here is my bootstrap.js

import Echo from 'laravel-echo'

window.io = require('socket.io-client');


window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001',
});

Here is the part of the client-side Vue component that listens for Echo events:

            Echo.channel('channelReceiveLiveData')
            .listen('liveDataTrigger', (e) => {
                that.$set(
                    that.state.labelDataSet, 
                    e.data.capture_timestamp, 
                    e.data.capture_timestamp
                );
                that.pushTestData(e.data);
            });

Everything is working as expected. What I am trying to do now is to also send over data from the client-side (VueJS component) to Laravel (so data can be stored in the app database) by utilizing the WebSocket connection. I am trying to avoid sending multiple AJAX requests, as I need to send data to the server every second, and I have noticed that sending too many consecutive HTTP requests at once results in several being dropped.

I would imagine something like this would exist:

Echo.emit('test')

But it seems Laravel Echo wasn't designed to support the emission of events back to Laravel.

Any advice on how to accomplish this? My guess is that I would have to somehow use the broadcaster (socketIO) to send the message over to the laravel-echo-server, but I have no clue as to how one would do this.

19 May
1 year ago

mdobrenko left a reply on Laravel Echo & AJAX Requests

To clarify -- I want the client to be able to utilize websockets to send data to the server, not only retrieve. Is this possible using Laravel Echo, or would I need to use something like Socket.io to accomplish this?

I am currently using Pusher + Laravel Echo, which seemingly only allows you to send data to the client from the server, not the other way around.

mdobrenko started a new conversation Laravel Echo & AJAX Requests

I am not sure if Laravel Echo would support this particular functionality, as I can't seem to find anything in the documentation.

I understand that Laravel Echo provides live updates to the client-side (when you set up a listener) whenever an event is triggered on the server. In my particular case, I have requests sent to the server via an AJAX call every second or so, which calls a controller method that stores data in the database, and then triggers the event.

Is it possible to use Laravel Echo to somehow make requests to the server (utilizing the websockets) instead of AJAX to trigger the event, so as to avoid multiple HTTP requests made to the server?

mdobrenko started a new conversation Upgrading To Laravel 5.6

I was following the documentation to upgrade to laravel 5.6 from laravel 5.5, and get this error in the console:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.9
    - Conclusion: don't install laravel/framework v5.6.21
    - Conclusion: don't install symfony/http-kernel v3.4.7|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.8|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.6
    - Conclusion: don't install symfony/http-kernel v4.0.9|install symfony/http-kernel v3.4.6|install symfony/http-kernel v3.4.7|install symfony/http-kernel v3.4.8
    - Conclusion: don't install symfony/http-kernel v3.4.0|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.1|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.2|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.3|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.4|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/http-kernel v3.4.5|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/debug v4.0.2|install symfony/http-kernel v3.4.0|install symfony/http-kernel v3.4.1|install symfony/http-kernel v3.4.2|install symfony/http-kernel v3.4.3|install symfony/http-kernel v3.4.4|install symfony/http-kernel v3.4.5|install symfony/http-kernel v3.4.6|install symfony/http-kernel v3.4.7|install symfony/http-kernel v3.4.8|install symfony/http-kernel v3.4.9
    - Conclusion: don't install symfony/http-kernel v4.0.8|install symfony/http-kernel v3.4.3|install symfony/http-kernel v3.4.4|install symfony/http-kernel v3.4.5|install symfony/http-kernel v3.4.6|install symfony/http-kernel v3.4.7|install symfony/http-kernel v3.4.8|install symfony/http-kernel v3.4.9
    - Conclusion: don't install symfony/http-kernel v3.3.16|install symfony/http-kernel v4.0.8|install symfony/http-kernel v4.0.9|install laravel/framework v5.6.21|install laravel/framework v5.6.22
    - Conclusion: don't install symfony/debug v4.0.1|install symfony/http-kernel v3.3.16|install symfony/http-kernel v3.4.0|install symfony/http-kernel v3.4.1|install symfony/http-kernel v3.4.2|install symfony/http-kernel v3.4.3|install symfony/http-kernel v3.4.4|install symfony/http-kernel v3.4.5|install symfony/http-kernel v3.4.6|install symfony/http-kernel v3.4.7|install symfony/http-kernel v3.4.8|install symfony/http-kernel v3.4.9
    - Conclusion: don't install symfony/debug v4.0.9
    - Conclusion: don't install symfony/debug v4.0.8
    - Conclusion: don't install symfony/debug v4.0.7
    - Conclusion: don't install symfony/debug v4.0.6
    - Conclusion: don't install symfony/debug v4.0.5
    - Conclusion: don't install symfony/debug v4.0.4
    - Conclusion: don't install symfony/debug v4.0.3
    - Installation request for laravel/cashier ~7.0 -> satisfiable by laravel/cashier[v7.0.0, v7.0.1, v7.0.10, v7.0.11, v7.0.12, v7.0.13, v7.0.2, v7.0.3, v7.0.4, v7.0.5, v7.0.6, v7.0.7, v7.0.8, v7.0.9, v7.1.0].
    - laravel/framework v5.6.0 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.1 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.10 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.11 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.12 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.13 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.14 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.15 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.16 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.17 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.18 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.19 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.2 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.20 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.3 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.4 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.5 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.6 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.7 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.8 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - laravel/framework v5.6.9 requires symfony/debug ~4.0 -> satisfiable by symfony/debug[v4.0.0, v4.0.1, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
    - Conclusion: don't install symfony/debug v4.0.0
    - Installation request for laravel/framework 5.6.* -> satisfiable by laravel/framework[v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.18, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.3, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9].

my composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "laravel/cashier": "~7.0",
        "laravel/framework": "5.6.*",
        "laravel/passport": "^5.0",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "^5.5.0",
        "pusher/pusher-php-server": "~3.0",
        "fideloper/proxy": "~4.0",
        "nesbot/carbon": "1.25.*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~7.0",
        "filp/whoops": "~2.0"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\Foundation\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\Foundation\ComposerScripts::postUpdate",
            "php artisan optimize"
        ],
        "post-autoload-dump": [
        "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover"
        
]    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

It looks like the problem has something to do with symfony/debug; but the errors indicate that the http kernel may also be outdated (?)

13 Jul
2 years ago

mdobrenko left a reply on Retrieve Only Specific Columns From Find() Method

Found this shortly after posting... should have looked a little bit longer.


        return Auth::user()->some_model()->find($id, ['col_a', 'col_b']);

Apparently the answer lies in adding the columns to the find function.

mdobrenko started a new conversation Retrieve Only Specific Columns From Find() Method

Intuitively, I would think that if you would like to retrieve only specific values from a model that is retrieved in Eloquent using the find method, it would look something like this:

        return Auth::user()->some_model()->find($id)->get(['col_a', 'col_b']);

What it seems to do, however, is return ALL models in the database with 'col_a', 'col_b' values for each of the models (associated with that user in particular).

How would one only get the model returned by the find($) and then grab those two columns? Worth noting this is in Laravel 5.4

23 Jun
2 years ago

mdobrenko started a new conversation VueRouter, VueJS, And Laravel Route Guard

I wanted to hide a particular page of my application behind a layer of security (a simple passcode form that will send a request to the server for validation).

Based off the documentation of VueRouter, I figured a beforeEnter would be appropriate. However, I am not entirely sure how one would require a user to access a particular component, and then successfully enter a passcode before being allowed to proceed to this current route.

Does anyone have an example of this? I am having trouble finding anything similar.

import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const routes = [
  { path: '/test/:testURL', component: require('./components/test.vue'), 
    beforeEnter: (to, from, next) => {
           // somehow load another component that has a form
           // the form will send a request to Laravel which will apply some middleware
           // if the middleware successfully resolves, this current route should go forward. 
    }
  },
];

const router = new VueRouter({
  routes,
  mode: 'history',
});

const app = new Vue({
  router
}).$mount('#app');

20 Jun
2 years ago

mdobrenko started a new conversation VerifyCSRFToken Error On Returning View In Middleware

I am trying out middleware for the first time, and I seemingly keep running into this issue when attempting to return a view:

Call to a member function setCookie() on null

As I understand it, this is occurring in the VerifyCsrfToken middleware, which is attached to the 'web' group.

Here is the routes file:

<?php

Route::get('/test/{id}', function() {
    return View('layouts.test');
})->middleware('test.auth');

Auth::routes();

// Catch any other requests
Route::get('/{catchall?}', ['as' => 'start', 'middleware' => 'auth', function() {
    return view('home')->with([
        'firstName' => Auth::user()->firstName, 
        'lastName' => Auth::user()->lastName
    ]);
}])->where('catchall', '.*');

And the Kernel.php file:

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        // this is the middleware in question
        'test.auth' => \App\Http\Middleware\VerifyTestAccess::class,
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];
}

And the middleware:

<?php

namespace App\Http\Middleware;

use Closure;

class VerifyTestAccess
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {   

        $passcode = true;

        if($passcode) {
            return View('authenticate');
        }

        return $next($request);
    }
}

authenticate view:

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ config('app.name', 'test') }}</title>
</head>
<body>
    You need to authenticate first
</body>
</html>

test view:

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ config('app.name', 'Test') }}</title>
</head>
<body>
    Sweet, you're authenticated!
</body>
</html>

Any ideas on what I may be doing wrong?

14 Jun
2 years ago

mdobrenko started a new conversation Moving On To Next Route If Some Url Cannot Be Found

I am working on an application using Laravel 5.4, VueJS, AXIOS, VueRouter. VueRouter is responsible for all of the navigation in the application, save for the route config below:


<?php

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

Auth::routes();


Route::get('/{catchall?}', ['as' => 'start', 'middleware' => 'auth', function() {
    return view('home')->with([...]);
}])->where('catchall', '.*');

This essentially redirects the user to the 'base' blade file, which contains the <router-link></routerlink>.

However, I am now implementing a page in my application that anyone can access (not requiring the auth middleware), and utilizes a different layout entirely (so needs a new blade file).

Preferably, it would be accessed like this:

app.sample.com/{some-string}

Rather than something else like this:

app.sample.com/survey/{some-string}

{some-string} is a randomly generated string that is then thrown into the DB. accessible by one of my models. As I understand it, I could do something like this:

Route::get('/{some-string}', '[email protected]')

Placing this above the catchall should work. However, in the case that /{some-string} does not match anything in the DB, I would prefer that it gets handled by the catchall, which will serve the home.blade.php

Is there any clean way to handle this?

08 Jun
2 years ago

mdobrenko left a reply on Querying Relationship Using With, Get Specific Entry

The reason I was including Auth::user() was to make sure the Test does indeed belong to that particular user. Using that solution and applying some auth:

    public function getTestData($id) {
         $user = Auth::user();
         $test = Test::with('testRecords')->find($id);
         if($user->tests()->find($id)->user_id == $user->id) {
             return $test;
         } 
        return 'fail';
    }   

But it just seems like a lot of trouble to authenticate. I will probably use this for the time being, but perhaps someone might know of a better way to do this?

mdobrenko left a reply on Querying Relationship Using With, Get Specific Entry

The code above gave me errors, but the equivalent approach (I think):

        return Auth::user()->with(['tests.testRecords' => function ($query) use($id) {
            $query->where('id', $id);
        }])->get();

This returns the user->tests->testRecords data, which isn't ideal because I don't need the all the user data being pulled in there. I would prefer to just have test->testRecord data for that user being returned alone.

mdobrenko started a new conversation Querying Relationship Using With, Get Specific Entry

Assuming a model User has a one to many relationship with Tests, and Tests has a one to many relationship with TestRecords, I wanted to return a Test with an id of $id, as well as its corresponding test records:

    public function getTestData($id) {
    return Auth::user()->tests()->find($id)
        ->with('TestRecords')
        ->get();
    }       

Unfortunately, what this does is pass back all tests, but only the test with an id of $id has test records returned with it. I tried this variation:

    public function getTestData($id) {
    return Auth::user()->tests()
        ->with('TestRecords')
        ->where('id', $id)
        ->get();
    }   

Unfortunately, this approach returns the tests without their corresponding records.

I am a bit confused as to why the first version returns ALL tests. In my mind, ->with is operating on a single Test object, and should only be returning the corresponding records.

04 Jun
2 years ago

mdobrenko started a new conversation AXIOS - {"error":"Unauthenticated."}

I am using Laravel 5.4, VueJS, and AXIOS. I have included the default AXIOS configuration file, and I can see in the request headers that the token is being passed:

X-CSRF-TOKEN:nzU9LU2DOo1TAedACwd1BmleL9RIzzHELFEimeOH
X-Requested-With:XMLHttpRequest
X-XSRF-TOKEN:eyJpdiI6IkpwQ2NOaVhxNmc5NjNIbUlUNnlyYVE9PSIsInZhbHVlIjoiYmVidFk3TWREMTFMZ1lFUG5qaGJwZ0NnenJKcDB2TFNZUWtnWEd4U2kyaUw3eU1qeXBqUHk5eGZwOUdNYnJ1dkQ1Y2hxNFNaRzlkQ2pzYnhlQlhqd3c9PSIsIm1hYyI6IjJiMTAyNDU3NmVlM2RmYmJkNzAzNTQ0ZDVhOWY2MDRiNTkyYmJhOWZlYTM3ZTFhZTZiYTk2NWM3YjcxZTk3N2MifQ==
Name

My config/auth.php file:

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

The actual request:

axios.get('/api/dashboard/')
.then(function (response) {
     that.state.entries = response.data;
})
.catch(function (error) {
     console.log(error);
});

Any advice on where I may be going wrong? I am not sure what I might have missed.

01 Jun
2 years ago

mdobrenko started a new conversation Bootstrap's Javascript Requires JQuery Error

I was trying to set up my project so that it would pull in bootstrap & jquery via npm. However, when attempting to do so, I get an error:

all.a3297c6….js:5607 Uncaught Error: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript.
    at Object../node_modules/bootstrap/dist/js/bootstrap.min.js

My webpack.mix.js file:

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */
 mix.js([
        '././node_modules/jquery/dist/jquery.min.js',
        '././node_modules/bootstrap/dist/js/bootstrap.min.js', 
        'resources/assets/js/app.js',
    ],'public/js/all.js').version();

 mix.styles([
        '././node_modules/bootstrap/dist/css/bootstrap.min.css',
        'resources/assets/css/theme/common.css', 
        'resources/assets/css/theme/animate+animo.css',
        'resources/assets/css/theme/csspinner.css',
        'resources/assets/css/theme/landing.css',
        '././node_modules/sweetalert/dist/sweetalert.css',
        'resources/assets/css/loader.css',
        '././node_modules/nouislider/distribute/nouislider.css',
        'resources/assets/css/theme/app.css',
    ], 'public/css/all.css').version();

My app.js file:


import Vue from 'vue'
import VueRouter from 'vue-router'
import axios from 'axios'
window.jQuery = window.$ = require('jquery');
import 'bootstrap'

window.Vue = Vue;
Vue.prototype.$http = axios;
Vue.use(VueRouter);

axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content')

//Helper file that contains loading screen logic
require('./helpers');

I am using Vue/Vue Router (not sure if that really matters). Any help is appreciated!

28 May
2 years ago

mdobrenko started a new conversation Laravel Mix Not Compiling JS File

I have this in my webpack.mix.js file:

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.scripts([
    'resources/assets/js/app.js'
], 'public/js/all.js').version();

This does not work, however. Mix seemingly just copies over the file exactly as it appears into public/js/. However, this alternative form works:

mix.js('resources/assets/js/app.js','public/js/all.js').version();

Any idea on why this may be? I will eventually be including multiple js files, and it is a lot cleaner to use mix.scripts()

15 May
2 years ago

mdobrenko started a new conversation Running Gulp Causes Vue-resource CSRF Token To Stop Loading

I recently set up a dev environment on my windows 10 machine. Everything seems to work well, except for gulp-related tasks. After editing my vueJS template files and running gulp, I get:

Uncaught TypeError: Cannot read property 'headers' of undefined
    at eval (eval at <anonymous> (all-e277d68f91.js:798), <anonymous>:11:49)
    at Object.<anonymous> (all-e277d68f91.js:798)
    at __webpack_require__ (all-e277d68f91.js:20)
    at Object.<anonymous> (all-e277d68f91.js:1109)
    at __webpack_require__ (all-e277d68f91.js:20)
    at all-e277d68f91.js:64
    at all-e277d68f91.js:67

The corresponding line that it is referring to:

Vue.http.headers.common['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content');

My all.js file, where I pull in vue, vue-resource, vue-router, etc:

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);
Vue.use(require('vue-resource'));


Vue.http.headers.common['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content');

Everything seemed to be working absolutely fine before making any change (adding an empty pair of span tags, for example) and then running gulp. In other words, after pulling the code from my git repository, and running gulp just to compile assets, things work fine. Any idea what the problem might be? I assume it must be related to gulp/webpack, but do not even know where to begin looking.

11 Apr
2 years ago

mdobrenko started a new conversation Generating Unique Strings For A URL

I have seen many different implementations of this for different languages/frameworks, but I am wondering if Laravel might not have some useful helper methods that may make this an easier task.

In short, I would like to generate a random, unique string for each instance of a resource in my project. Let's say the resource is a 'test'. Upon test creation, I would like to assign it said string, with the end goal of being able to allow people to access a given resource based on this generated, unique value:

test.app/af3123!
test.app/gxcr_2!

I don't really care if they are all the same length or not, though I would prefer not to have something longer than say 6-8 characters.

At first glance I figured just to generate random combinations of strings, and test to see if such a combination has been used in the database yet. However, I imagine that might get problematic if the database becomes sufficiently large.

Any ideas?

09 Jan
2 years ago

mdobrenko left a reply on Laravel 5.3 Unauthenticated

Hmm, I took it out of the constructor and simply attached it to the route, though apparently you are still allowed to do that in Laravel 5.3. It didn't seem to do anything (same error).

I have found that if I output the {{ Auth::check() }} in my blade file, it returns '1'. To me that says there must be an error in the way the api is configured, or I am calling Auth wrong? However, I followed the documentation and brought in the Facade, and I just noticed that you can apparently use the $request to grab the user in 5.3. However, all this still yields the same result...

Here is the controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Test;
use Illuminate\Support\Facades\Auth;

class TestController extends Controller
{
    //Create given a Resource
    public function store(Request $request) {
        $this->validate($request, [
            'test_name' => 'required',
            'test_id' => 'required',
            'is_live_test' => 'required',
        ]);

        $user = $request->user;
        
        if($user) {
            return 'We are logged in';
        } else {
            return 'We are not logged in';
        }
                return ' ';
    }
}

mdobrenko started a new conversation Laravel 5.3 Unauthenticated

Was having a bit of a problem getting the authentication to work. I am using the default Laravel 5.3 authentication, and successfully creating accounts, redirecting to the dashboard of my app. However, it seems that I am not able to perform anything that requires authentication:

The controller constructor:

    public function __construct()
    {
        $this->middleware('auth');
    }

The error:


error:"Unauthenticated."

These calls are all being handled by the api.php file.

Any ideas on what I should look into? I don't quite know where to begin...

mdobrenko left a reply on 5.3 API Routing

Ah, I had a feeling that it set the default prefix. Thanks!

mdobrenko started a new conversation 5.3 API Routing

I was trying to make a request to one of my API routes (defined in api.php):

<?php

use Illuminate\Http\Request;

Route::group(['prefix' => 'api', 'namespace' => 'Api'], function() {
    Route::get('test/create', '[email protected]');
});

However, I get a method not allowed (405). If I copy the route into web.php, it seems to work fine. I am testing by making both requests via the browser, and through VueJs with the same result.

Any ideas on what the problem may be?

07 Jan
2 years ago

mdobrenko started a new conversation Multi-step Form On Single Page App

I am using Vue-Router in my project, and wanted to create a multi-step form. I wasn't quite sure what the best way to go about doing this would be; my idea was that I would create a separate Vue component for each form-step, and pass data between them using the event emitter.

However, would this work? Is it possible to route to the component first, and then pass the data needed? Or are you supposed to pass the data first using the event dispatcher, and then route to the component (would this really matter)?

Jeffrey talked about this a bit in this video, but his example is what seems to be a parent and child component, whereas these components would be loaded one at a time by the vue-router. Not even sure what that makes them (siblings)?

Any advice appreciated!

mdobrenko left a reply on OTS Parsing Error: Invalid Version Tag

I realized I changed the paths, but they were set up for a project using versioning (and I am not). Thanks!

06 Jan
2 years ago

mdobrenko started a new conversation OTS Parsing Error: Invalid Version Tag

After deploying to a live server (set up on a 'develop' branch, local not prod) I found that bootstrap fonts were not being loaded correctly. This seems to work fine on my local environment...

Failed to decode downloaded font: http://dev.test.com/fonts/glyphicons-halflings-regular.woff2
/#/:1 OTS parsing error: invalid version tag
/#/:1 Failed to decode downloaded font: http://dev.test.com/fonts/glyphicons-halflings-regular.woff2
/#/:1 OTS parsing error: invalid version tag
/#/:1 Failed to decode downloaded font: http://dev.test.com/fonts/glyphicons-halflings-regular.woff
/#/:1 OTS parsing error: invalid version tag
/#/:1 Failed to decode downloaded font: http://dev.test.com/fonts/glyphicons-halflings-regular.woff
/#/:1 OTS parsing error: invalid version tag
/#/:1 Failed to decode downloaded font: http://dev.test.com/fonts/glyphicons-halflings-regular.ttf
/#/:1 OTS parsing error: invalid version tag
/#/:1 Failed to decode downloaded font: http://dev.test.com/fonts/glyphicons-halflings-regular.ttf
/#/:1 OTS parsing error: invalid version tag

And in my gulpfile:

    mix.copy('node_modules/bootstrap/dist/fonts', 'public/build/fonts');
    mix.copy('node_modules/font-awesome/fonts', 'public/build/fonts');

Local webpack.config.js:


module.exports = {
    entry: __dirname + "/index.js",
    output: {
        path: __dirname + "/",
        filename: "specs.js"
    },
    module: {
        loaders: [
            { test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: [['es2015', {modules: false}]]}},
            { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
            { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }
        ]
    }
};

Any idea on what the culprit may be? Not sure why the fonts aren't being loaded.

02 Jan
2 years ago

mdobrenko left a reply on Webpack/Elixir Not Updating CSS?

Totally didn't know you could do that. I just thought the cache would update automatically...

mdobrenko started a new conversation Webpack/Elixir Not Updating CSS?

I've encountered a rather interesting situation. I am using web pack, elixir for a project and am having trouble getting my CSS to update. More specifically, I find that the browser for some reason appears to be disregarding (or not noticing) the changes:

Picture 1

But, clicking on the app.css:383 in the browser gives me this:

Picture 2

The property of interest here is margin-left. Any ideas on why this may be happening? Is there some sort of caching process that web pack may be calling that is causing this?

31 Dec
2 years ago

mdobrenko left a reply on Webpack And Bootstrap Glyphicons

Thanks a ton! :-)

30 Dec
2 years ago

mdobrenko started a new conversation Webpack And Bootstrap Glyphicons

First time using webpack, and I'm running into problems with loading bootstrap glyphicons:

Image of error

As I understand it, by default app.scss pulls in sass-bootstrap automatically without much additional work on my end, with the exception of adding the necessary loaders:

module.exports = {
    entry: __dirname + "/index.js",
    output: {
        path: __dirname + "/",
        filename: "specs.js"
    },
    module: {
        loaders: [
            {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: [['es2015', {modules: false}]]}},
            {test: /\.woff2?$|\.ttf$|\.eot$|\.svg$/, loader: "url"}
        ]
    },
    publicPath: 'build/'
};

And my app.js file, where the router config is being set:

...
var Vue = require('vue');
var VueRouter = require('vue-router');
window.$ = window.jQuery = require('jquery');
require('bootstrap-sass');

...

I must be missing something... any advice?

17 Aug
3 years ago

mdobrenko started a new conversation JQuery Not Detecting Dynamically Generated HTML?

I have a series of folders that are represented as links using a v-for (data pulled from API). For each of those links, I am using a library called x-editable to allow for the editing of the names.

I find that if I create a dummy link (outside of the for loop) and include the instantiation in a document.ready block, it works just fine:

    ready: function() {
        jQuery.fn.editable.defaults.mode = 'popup';
        jQuery('.editable').editable();
    },

However, none of the links generated by the v-for work. My guess is that jQuery is simply not detecting them, as they were not made when the document was loaded.

I read that you can bind events using .on() which will work with generated elements. However, .editable() isn't really an event. Is there a way to get around this?

27 Jul
3 years ago

mdobrenko left a reply on File Download Using AJAX?

Ended up realizing that it simply won't work via an AJAX call - had to use window.location instead, which isn't ideal, but still works.

mdobrenko started a new conversation Eager Loading & OrderBy

As I understand it, you could apply an orderBy operation to an eager loading code block as such:

        return $this->user->folders()->with(['folders.subscribers' => function($query){
            $query->orderBy('created_at', 'desc');
        }, 'folders.notifications'])
        ->get();

However, this would sort by the 'subscribers' table created_at, rather than the 'folders' table created_at. Any ideas on how I could work around this? I was hoping I could specify what table the orderBy is operating on, but nothing seems to work.

26 Jul
3 years ago

mdobrenko started a new conversation File Download Using AJAX?

I am using Laravel Excel to generate a spreadsheet. The method that generates to the spreadsheet is linked to a route:

export/messages

This works fine if I navigate to it manually in the browser. However, I am using the VueJS Router for the actual navigation of the app, as well as the front-end, and thus if I use a method such as this:

            export: function() {
                this.$http.get('export/messages').then(function(response) {
                    return response; //I've tried doing several things here, this was my last desperate attempt
                });
            }

The actual file download will not trigger. Any suggestions/tips on how to get this to work?

11 Jul
3 years ago

mdobrenko started a new conversation Abort() Not Changing Headers

So this is an abort call that I wrote which is within a DB::transaction() block:

 abort(422, 'insufficient_credits', ['statusText' => 'insufficient_credits']);

Unfortunately, it does not modify the actual headers of the response. Instead, it seems to be creating headers within some nested scope... not really sure how to access it:

Response Image

My JavaScript file where the call is made:

this.$http.post('/api/test', data).then(function(response) {
//Stuff here                
},  function(response)  {
if(response.status === 422)  {
//This triggers the output in the screenshot above
console.log(response); 
}});

How can I modify my code/abort error so that it actually modifies the header value? If that's not possible, is there any way of passing back and retrieving additional information alongside the response status?

07 Jul
3 years ago

mdobrenko started a new conversation Align Bootstrap Header + Elements?

https://jsfiddle.net/5nj5nmqz/5/

    <div class="row">
        <h1 class="page-header">Header</h1>
        <div class="col-md-4">
            <a href="#" class="btn btn-default pull-right export">
                Export spreadsheet
                <i class="fa fa-download"></i>
            </a>
        </div>
        <div class="col-md-4">
            <div class="form-group has-feedback pull-right">
                <input type="text" class="form-control search pull-right" v-model="private.searchQuery" v-on:focus="$broadcast('reset-pagination')" placeholder="Search by check name...">            
                <i class="glyphicon glyphicon-search form-control-feedback"></i>
            </div>
        </div>
    </div>

Having a bit of trouble getting my elements to align in the same row as the bootstrap header. Any ideas?

07 Jun
3 years ago

mdobrenko left a reply on Delete For HasMany?

Oddly enough, I went through and tried doing that, and other variations, but the problem was another bit of my code which I neglected to change, and so when I tried that originally, I though it wasn't working. This ended up being right.

mdobrenko started a new conversation Delete For HasMany?

I've been trying to implement a delete statement, but nothing seems to be working:

$group->users()->delete;
$group->notifications()->delete;

This doesn't seem to work, however. Any ideas?

03 Jun
3 years ago

mdobrenko left a reply on Filter Eager Loading Data

Shortly after posting, I found that this works:

 public function ungrouped() {
        $groups = $this->user->groups()->with('members')->where('folder_id','=','null')->get();
        return $groups;
    }

Something as simple as flipping the position of the with and the where.

mdobrenko started a new conversation Filter Eager Loading Data

Is it possible to filter out data before with() runs, using a where() statement like this:

    public function ungrouped() {
        $groups = $this->user->groups()->where('folder_id','=','null')->with('members')->get();
        return $groups;
    }

The documentation presented a way you could include a custom query, though it seems that only applies to the model being pulled in the with() statement.

31 May
3 years ago

mdobrenko left a reply on Eager Loading Filtering Data

That's cool - did not know you could do that! It seems they both result in a single query - personally the first appeals to me more, looks a lot cleaner.

EDIT: Also modified the output a bit, seems that the first option is .1 slower. I wonder how that will scale with the database size

mdobrenko started a new conversation Eager Loading Filtering Data

Trying to decide on the best way to filter out data that is relevant only to the current authenticated user. There are two ways that I can think of. In this example, I'm grabbing the folders associated with a user, and some more models associated with those aforementioned folders.

  1. Filter out the folders first with a call to a Eloquent relationship. I'm not sure how many queries this results in:
      $folders = $this->user->folders()->with('checks.members','checks.notifications')->get();
  1. Grab everything, filter out afterwards (Seems... inefficient? What if you have 5 million records?)
        $folders = Folder::with('checks.members','checks.notifications')->get();
    $folders = $folders->where('user_id','=',$this->user->id)->get();

Any tips?

mdobrenko left a reply on Nested Object Arrays And V-for

For anyone with a similar problem in the future:

The syntax I provided is valid. The reason it didn't work is because I was using v-for in a element, and vue selectors and operations can behave oddly when they modify the values of elements in tables.

30 May
3 years ago

mdobrenko started a new conversation Nested Object Arrays And V-for

Having a bit of trouble getting nested for-loop data to show up:

<div v-if = "private.folders!=null" v-for="folder in private.folders">
    <div v-for="check in folder.checks">
        {{check.name}}
    </div>
</div>

And then the data that I'm trying to use looks like this:

folders [Array]
-object [this is a single 'folder']
--name
--created_at
--updated_at
--checks [array] [each folder has this array]
---[object] [the actual 'check' object]
----[name]
----[type]
----[etc]

The outer loop works just fine, and returns the data I expect. However, check.name doesn't return anything, and there are no errors in the console. Is it possible to do nested for-loops like this?

27 May
3 years ago

mdobrenko started a new conversation Updating Database Based On Changing Data In Array

I'm currently working on an app where I pull in data via a GET request that returns an array of objects, which I populate the page with, and allow the user to edit directly.

I'm a little bit unsure of how to approach updating the data in the database - basically, how can I tell which records have changed, or only update the entries in the database for which the data has changed? The way I would do this is simply copy the array of returned records into another array, and then compare it to the edited one after all changes have been made through some custom-made function.

However, I feel like there is a better way to do this with PATCH or PUT requests - any ideas?

26 May
3 years ago

mdobrenko left a reply on DB Query Formatting Data

D'oh, figured out right after I posted that I can do this:

$data['groupMembers'] = DB::table('group_member')->select('group_id','invitation_id','user_id')->whereIn('id', $checkGroupMembers)->get();

(Removing the extra [])

mdobrenko started a new conversation DB Query Formatting Data

I have an API in my backend that is returning data I need to use in Vue. At present though, it seems to be returning an array of objects, which has an array of fields inside of it. Here is the API line with the relevant query:

$data['groupMembers'][] = DB::table('group_member')->select('group_id','invitation_id','user_id')->whereIn('id', $checkGroupMembers)->get();

And here is the result assigned to a 'test' variable as seen through VueDevTools:

img

I could use a nested for-loop to filter the data, but I would rather return just an array with the fields that are listed in the select() statement. Any ideas?

24 May
3 years ago

mdobrenko started a new conversation Relationship Between Two Tables Via Two Separate Pivots

I'm having a tough time wrapping my head around this problem. Assume there are two tables:

-Group (which has a pivot table group_members, which takes into account different types of users, etc)
-Notifications

Now, the relationship I wanted to model was between Notifications and group_members, as every group member can be the recipient of a notification, and a single notification can be sent out to multiple recipients. This seems to require another pivot table: notification_group_members.

So, really, what it seems to be is that I have a relationship between two pivot tables. It would be easy to come up with a solution simply using DB::(), but I would prefer to use the existing models I have, and not have to create new models for the pivot tables. Is there a way to do this? Any ideas?

16 May
3 years ago

mdobrenko started a new conversation [Please Delete]

[Please Delete]