Edelco

Experience

6,190

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 57 Lessons Completed
  • 10 Favorites

17th January, 2018

Edelco left a reply on Laravel Itterate Through Arrays In An Array • 1 month ago

@nadj

    @foreach($data as $items)
        @if($items)
                @foreach($items as $subitem)
                    {{ dd($subitem) }}
                @endforeach
        @endif
    @endforeach 

this returns an empty array in the blade view.

Edelco started a new conversation Laravel Itterate Through Arrays In An Array • 1 month ago

I have the following dd from a API query:

array:22 [▼

0 => array:3 [▼ 0 => {#436 ▼ +"applicationInstance": "definst" +"name": "myAmsterdam" +"sourceIp": "rtmp://xx.xx.xx.xx:{portnumber}" +"isRecordingSet": false +"isStreamManagerStream": false +"isPublishedToVOD": false +"isConnected": true +"isPTZEnabled": false +"ptzPollingInterval": 2000 +"ptzPollingIntervalMinimum": 1000 } 1 => {#418 ▶} 2 => {#409 ▶} ] 1 => [] 2 => [] 3 => [] 4 => array:3 [▶] 5 => [] ]

How will I be able to itterate over this so I can call the data from "name" and "isConnected" ?

Edelco left a reply on Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

@Cronix I fixed it with using:

 return view('streams.api', compact('data'));

The dd($data) now shows all API request. Thanks a lot !

Edelco left a reply on Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

@Cronix Did a dd($data) and seems that it is not returning $data to my blade view:

 Undefined variable: data

Edelco left a reply on Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

@Cronix Thanks for your effort. Still error:

 (2/2) ErrorException

Trying to get property of non-object (View: /home/vagrant/sites/kerkdienstuitzending.nl/resources/views/streams/api.blade.php)

Edelco left a reply on Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

@Cronix

Still an error:

 (2/2) ErrorException
 Undefined variable: incomingStreams (View: 

/home/vagrant/sites/kerkdienstuitzending.nl/resources/views/streams/api.blade.php)

Edelco left a reply on Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

@Cronix

     public function getDataFromApi()
{

    $cong = Stream::pluck('name');

    foreach($cong as $gemeente)
    {
        $client = new Client([
            'headers'  => [
                'content-type' => 'application/json',
                'Accept' => 'application/json',
            ],
        ]);

        $response = $client->request('GET', 'http://86.87.11.55:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/'.$gemeente.'/instances/_definst_');

        $decoded = json_decode($response->getBody());

        // add to data array instead of overwriting
        $data['incomingStreams'][] => $decoded->incomingStreams;
    }
    
    return view('streams.api', compact('data'));
     }

Gives me an error:

 (1/1) FatalThrowableError
 Parse error: syntax error, unexpected => (T_DOUBLE_ARROW)

 in StreamsController.php (line 51)

Edelco left a reply on Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

@thomaskim : True. Didn't think of it that way. All I want is the complete list. I know when a stream is not connected it will return an empty array (in JSON) but I also know that when there IS an active stream it will return an array ($data) where I want to get the "incomingStreams".

Edelco started a new conversation Problem With Returning A Foreach Loop From Laravel Controller To Blade View • 1 month ago

I am trying to do a foreach loop in a curL request in a method of a controller.

method (from StreamsController):

public function getDataFromApi() {

$cong = Stream::pluck('name');

foreach($cong as $gemeente)
{
    $client = new Client([
        'headers'  => [
            'content-type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ]);

    $response = $client->request('GET', 'http://xx.xx.xx.xx:xxxx/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/'.$gemeente.'/instances/_definst_');

    $data = $response->getBody();
    $data = json_decode($data);
    $data = $data->incomingStreams;
}

return view('streams.api', compact('data'));

}

My blade page:

@extends('layouts.app')

@section('content') {{ dd($data) }} @foreach($data as $result)

{{ $result->name }}

@endforeach

@endsection

But when I try to output the result in a blade view page doing a diedump it returns an empty array [] while I know for certain it should return at least ONE result of an active stream.

What am I doing wrong?

19th August, 2017

Edelco left a reply on How To Get Client Ip Address In Register Controller In Laravel 5.3 With Passport Enabled • 6 months ago

Thanks @anonymox .. I needed that too and works. I use it when an user activates his/her account.

17th August, 2017

Edelco started a new conversation Laravel 5.4 Passing Form Select Option Value To A Route::get Ask • 6 months ago

I am trying to do the following within my Laravel 5.4 project.

In a users.index blade page I am listing all users from a database in a table. All the users belong to a district. Some districts have more users then the other.

At the top of this table view I created a form with a select field. The options hold the id's for the 10 districts:

<form class="form-horizontal" method="GET" action="/users/district">

            <div class="form-group col-md-5">
                <select name="district" class="form-control">
                    <option value="1">Amsterdam</option>
                    <option value="2">Arnhem</option>
                    <option value="3">Assen</option>
                    <option value="4">Groningen</option>
                    <option value="5">Leeuwarden</option>
                    <option value="6">Rotterdam</option>
                    <option value="7">Sittard</option>
                    <option value="8">Tilburg</option>
                    <option value="9">Utrecht</option>
                    <option value="10">Antillen</option>
                </select>
            </div>

            <div class="form-group col-md-4 col-md-offset-1">
                <button class="btn btn-md btn-primary">Haal gegevens op</button>
            </div>

            </form>

When I put the URL "http://localhost/users/district/5" in manually in the browser it shows me a table view with only users from the district with the ID of 5.

This is my UsersController:

public function perDistrict($district)
{
    $users = User::where('district_id', $district)
    ->paginate(12);

    $totalusers = User::count();

    return view('users.index', compact('users', 'totalusers'));
    }

I would like to use the form to get me the results but when I submit the form it show me this URL: "http://localhost/users/district?district=5" and it gives me no result of course.

How can I convert that to the URL "http://localhost/users/district/5" ?

This my route:

Route::get('users/district/{district}', '[email protected]');

Hope someone can help me.

13th August, 2017

Edelco left a reply on Refresh A DIV In Laravel Every 5 Seconds • 6 months ago

@m7vm7v Also thanks to your contribution. Will definitely have a look at it !!

Edelco left a reply on Refresh A DIV In Laravel Every 5 Seconds • 6 months ago

@isaackearl Thanks .. will have a look at it.

12th August, 2017

Edelco left a reply on Refresh A DIV In Laravel Every 5 Seconds • 6 months ago

@Snapey : So this can be the same Route as my index like

Route::get('streams', '[email protected]');

or do I have to create a new method and route?

BTW: The script fails due to this error:

Uncaught SyntaxError: Unexpected token }

This is my adjusted script placed in de app layout file section:

      <script>

    (function () {
        setInterval(function () {
            axios.get('streams',)
                .then(function(response){
                        document.querySelector('#partial')
                                .innerHtml(response.data);
                }); // do nothing for error - leaving old content.
            }); 
        }, 5000); // milliseconds
    })();

    </script>

11th August, 2017

Edelco left a reply on Refresh A DIV In Laravel Every 5 Seconds • 6 months ago

@rizwanjaved : Can you explain what exactly it is you mean by that? I am a totaly noob at AJAX.

Edelco left a reply on Refresh A DIV In Laravel Every 5 Seconds • 6 months ago

Extra info:

And here is the partial view that needs to be refreshed:

<div class="row images" id="partial">
</div>

Edelco started a new conversation Refresh A DIV In Laravel Every 5 Seconds • 6 months ago

Hello,

I started learning Laravel a little while ago and almost finished my Laravel 5.4 project. There is just one thing I can't get working and that is refreshing only a particular DIV section in a overview blade page. I looked and tried with javascript examples but it doesn't work. So hopefully someone can help me out.

I have a page which shows a list of available live streams. I want to change that status from offair to live if the status in my mySQL databse is changed (manually at first) I need to refresh that page every 5 seconds so viewers can see if a stream status is live or offair.

From examples I tried the following javascript (placed in the header section):

<script>

    (function () {
        setInterval(function () {
            axios.get('layouts.partials.refreshstreamoverview',)
                .then(function(response){
                        document.querySelector('#partial')
                                .innerHtml(response.data);
                }); // do nothing for error - leaving old content.
            }); 
        }, 5000); // milliseconds

</script>

My Route is:

Route::group(['prefix' => 'streams'], function () {

        Route::get('', '[email protected]');

    });

@index gives me all the streams available (whether offair or live)

My StreamsController looks like this:

<?php

namespace App\Http\Controllers;

use App\District;
use App\Gemeente;
use App\User;
use App\Stream;
use Illuminate\Http\Request;

class StreamsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $streams = Stream::orderBy('district_id')
        ->orderBy('gemeente_id')
        ->get();

        return view('streams.index', compact('streams'));
    }

}

Nothing gets refreshed after 5 seconds unfortunatly. Does someone have any idea how I can solve this? Much appreciated !

2nd August, 2017

Edelco started a new conversation Laravel Multiple Parameters In Route Middelware Not Working • 6 months ago

I have problem that using multiple parameters in my Route::middleware isn't working for me. I am trying to assign a specific route only accessible for a superuser and admin role.

When I just use:

role:superuser it works fine, but when I add a second parameter like:

role:superuser,admin it fails when I assign myself the admin role but still works for the superuser role.

I am confused so any help would be appreciated!

Here is my RoleMiddleware:

namespace App\Http\Middleware;

use Closure;

class RoleMiddleware {

/**

  • Handle an incoming request.
  • @param \Illuminate\Http\Request $request
  • @param \Closure $next
  • @param string $roles
  • @return mixed */

public function handle($request, Closure $next, ...$roles) { $user = $request->user();

if ($user && $user->isSuperuser($roles)) {
    return $next($request);
}

return redirect('/home')->withError('U heeft niet de juiste rechten!');

}

}

Here is my isSuperuser method in my User model:

public function isSuperuser(...$roles) { if ($roles) { return $this->roles == $roles; }

return $this->roles;

}

Last but not least my routes/web code for the middleware:

Route::get('/users', '[email protected]')->middleware(['role:superuser,admin']); Btw: the method is called 'isSuperuser' but that's just a name. It also has to accept the admin role at some point.

1st August, 2017

Edelco left a reply on Middleware Parameters - Comma Separated [5.2] • 6 months ago

I have a similar problem but no solutions above are working for me, so hopefully someone can help me out.

Here is my RoleMiddleware:

namespace App\Http\Middleware;

use Closure;

class RoleMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string $roles * @return mixed */ public function handle($request, Closure $next, ...$roles) { $user = $request->user();

    if ($user && $user->isSuperuser($roles)) {
        return $next($request);
    }

    return redirect('/home')->withError('U heeft niet de juiste rechten!');
    
}

}

Here is my isSuperuser method in my User model:

public function isSuperuser(...$roles)
{
    if ($roles) {
        return $this->roles == $roles;
    }

    return $this->roles;
}

Last but not least my routes/web code for the middleware:

Route::get('/users', '[email protected]')->middleware(['role:superuser,admin']);

So when I use only role:superuser it works fine, but when I add a second parameter it fails when I assign myself the Admin role.

Any help would be appreciated !!

24th July, 2017

Edelco left a reply on Can We Track Last Login Date Of Authorised User • 6 months ago

@garethdaine : Works perfect for me. Thanks for the explanation!

20th July, 2017

Edelco left a reply on Add Default Value To Pivot Table (users_role) When Creating A New User • 7 months ago

Not all my text was rendered. Don't know why but will place it here:

Hello,

Been searching the internet to get an answer to my problem.

I created a Roles/Permissions ability in my Laravel project by taking a videocourse. It uses pivot tables. My database contains the following standard Laravel tables after php artisan make:auth (and migrate):

  • users
  • password_resets

For the roles/permissions ability I created the following tables:

  • roles (id, name)
  • permissions (id, name)
  • roles_permissions (role_id, permission_id)
  • users_roles (user_id, role_id)
  • users_permissions (user_id, permission_id)

I also created a Trait:

Edelco started a new conversation Add Default Value To Pivot Table (users_role) When Creating A New User • 7 months ago

Hello,

Been searching the internet to get an answer to my problem.

I created a Roles/Permissions ability in my Laravel project by taking a videocourse. It uses pivot tables. My database contains the following standard Laravel tables after php artisan make:auth (and migrate):

  • users
  • password_resets

For the roles/permissions ability I created the following tables:

  • roles (id, name)
  • permissions (id, name)
  • roles_permissions (role_id, permission_id)
  • users_roles (user_id, role_id)
  • users_permissions (user_id, permission_id)

I also created a Trait:

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.