alphadev
590
21
Laravel

no data is showing from db

Posted 1 month ago by alphadev

firstly I was getting all data into a dropdown then i tried to get all the matching data (tried to match the logged-in user email or name with filename) into dropdown, (which includes two diff. tables), like one table is "users" and other is "files" i.e: in files table column(filename) diff. filename is John Doe, Erik Doe, Wak Edge ,,, and in users table a name is Doe and email is [email protected] , If a user login from [email protected] then he gets all data having Doe at its end. but it gives no outputt:

controller:

    public function index(Request $request)
    {

    $files = File::all();
        //dd($files);
    if (Auth::user()->admin == 0) {
        $selectedFile = File::find($request->Student);
        $file = Auth::user()->files;
        return view('home', compact('file', 'files', 'selectedFile'));
    } else {
        $users['users'] = \App\User::all();
        return view('layouts.master', $files);
    }

    $users = DB::table('users')->select('name', 'email as user_email')->get();
    DB::table('users')
    ->join('files', function ($join) {
        $join->on('users.id', '=', 'files.user_id')
             ->where('files.user_id' == 'filename');
    })
    ->get();
   }

blade file:

     <div class="form-group">
              <form oninput="this.submit()">
                <label class="text-left">Select Student</label>
                @if (Auth::user()->email == filename)
                    <select name="Student" id="Student" style="padding: 5px; border-radius: 3px;">
                      <option value="">Select Student</option>
                      @foreach ($files as $file)
                      <option value="{{ $file->id }}">{{ $file->filename }}</option>
                      @endforeach
                    </select>
                @endif
              </form>
            </div>

these are both tables:

      Schema::create('users', function (Blueprint $table) {
         $table->bigIncrements('id');
         $table->string('name');
         $table->string('email')->unique();
     });

   Schema::create('files', function (Blueprint $table) {
      $table->bigIncrements('id');
      $table->string('filename');
      $table->timestamps();
  });

m getting all records using this code: https://paste.ofcode.org/35ZJsiPqnLDW5BwYrz2AgAj

Please sign in or create an account to participate in this conversation.