lundi 25 septembre 2017

how to find ID in laravel 5.4

Hi i have this script which i really want to get the auth user ID when logged in. When logged in i want that the users id and only from the addrecords table will only display. Here is my code below

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Addrecord;
use App\User;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(){
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(){
        $ids = Auth::User()->id;
        echo $ids; 
        $datas = Addrecord::all()->toArray();
        echo "<pre>";
        print_r($datas);
        echo "</pre>"; 

        return view('home', compact('datas'));
    }
}

I want this line of code here

$datas = Addrecord::all()->toArray();

that line of code really works but i want that only user id from the table addrecord will only be displayed. Not all will be displayed but only the loggedIn user.

Any help is muchly appreciated. TIA



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hsLy6h
via IFTTT

Aucun commentaire:

Enregistrer un commentaire