Sunday, May 21, 2017

Ajax + Laravel 5.2 + add an attribute to each of the buttons, buttons are generated by @foreach loops

My view:

@foreach ($social_networks as $social_network)
    
@endforeach

My Controller:

$social_networks = DB::table('social_networks')->get();

if(Auth::user()->admin)
{
    return view('adminDashboard')
            ->with('social_networks', $social_networks)
            ->with('i', ($request->input('page', 1) - 1) * 9);
}
return view('dashboard')
            ->with('social_networks', $social_networks)
            ->with('i', ($request->input('page', 1) - 1) * 9);

My route:

Route::resource('dashboard','DashboardController');

Basically, what i need is, to try and add a url link to each of the buttons that get generated. And each of the buttons link will be different.

I need to add an attribute to each of these buttons. Let's call it data-url. In there I put the URL of the network And i need to attach a handler that fires when the button is clicked so that the URL is followed.



via Gesdev Webdev

Advertisement