Im new to laravel and im currently trying to get all the same user types as the one currently logged in to display on a table. For example, if a teacher ,html,laravel"/>

首页 > 解决方案 > LARAVEL: How to display all the same user type as the one currently logged in on a ?

Im new to laravel and im currently trying to get all the same user types as the one currently logged in to display on a table. For example, if a teacher

问题描述

Im new to laravel and im currently trying to get all the same user types as the one currently logged in to display on a table. For example, if a teacher is logged in, then all the other teacher type users must be listed on the table, only the teachers, no students no etc. I am currently using the make auth thingy.

table code

<table class="table table-striped table-bordered">
    <thead class="bg-danger">
      <tr>
        <th scope="col">First</th>
        <th scope="col">Email</th>
        <th scope="col">Type</th>
        <th scope="col">Action</th>
      </tr>
    </thead>
    <tbody>
      @foreach($users as $user)
        <tr>
          <td>{{ $user->name }}</td>
          <td>{{ $user->email }}</td>
          <td>{{ $user->user_type }}</td>
          <td style="width: 13%">
          <button type="button" class="btn btn-primary">{{ __('Edit') }}</button>
          <button type="button" class="btn btn-primary">{{ __('Delete') }}</button>
          </td>
        </tr>
      @endforeach
    </tbody>
  </table>
  </div>

Controller code


    public function index()
    {
        $users = User::all();

        return view('users.index')->with([
            'contentheader' => 'Users',
            'users' => $users,
        ]);
    }

migration code

 public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('username', 20)->unique();
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->enum('user_type',['teacher','student']);
            $table->rememberToken();
            $table->timestamps();
        });
    }

How can I hide the new url bar on iPad Safari WebApp fullscreen mode, appearing since iPadOS 13?

iPadOS 13 now shows a white/grey bar when a WebApp is installed via 'Add to Home Screen' on Safari, even when apple-touch-fullscreen meta tag is added. The bar includes a menu to resize font and request desktop site, but has affected the available screen size so that the users now have to scroll to view the app menu.

Is there any way to hide this bar, such as forcing either Desktop/Mobile site so that the selection is not required?

标签: htmllaravel

解决方案


首先在您的路由中添加中间件身份验证,如

Route::get('your route and related method')->middleware('auth');

并在您的控制器方法中运行查询,

use Auth;//don't forgot to add this
 public function index()
    {
       if(Auth::check())
       {
        $users = User::where('user_type',Auth::user()->user_type)->where('id','!=',Auth::user()->id)->get();
        return view('users.index')->with([         
            'users' => $users,
        ]);
      }

    }

推荐阅读