小编use*_*352的帖子

Laravel-如果登录凭据错误,则在同一页面上显示错误

我是Laravel的新手,并且我正在登录页面上工作,如果登录凭据错误,我想在该页面上在输入标签下方引发错误。我已经编写了一些代码,并且一切正常,但未显示错误。

看看我做了什么。

在控制器中:

public function login(Request $req) {

    $email = $req->input('email');

    $password = $req->input('password');

    $checkLogin = DB::table('admin')->where(['email'=>$email,'password'=>$password])->get();

    if(count($checkLogin) > 0) {
        echo "Login Successfull";
    }
    else {
        // echo "Login Failed!";
        return Redirect::route('admin-login')->with();
    }
}
Run Code Online (Sandbox Code Playgroud)

在视图中:

<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>

@if ($errors->has('email'))

<span class="help-block">

<strong>{{ $errors->first('email') }}</strong>

</span>

@endif
Run Code Online (Sandbox Code Playgroud)

途中:

Route::post('admin-login-result','AdminLoginController@login')->name('admin-log');
Run Code Online (Sandbox Code Playgroud)

谢谢

php laravel laravel-5

4
推荐指数
1
解决办法
5405
查看次数

Laravel - 在 web.php 以外的文件中创建路由

在 web.php 中制作网站各个页面的路由,使其变得庞大且非结构化。所以我的问题是有没有办法将它保存在单独的文件中?

// Calling Registration function
Route::any('/admin-store','AdminUserController@store')->name('admin-reg'); 

// Redirecting to Registration page
Route::get('/admin-registration','AdminUserController@index')->name('admin-registration'); 

// Redirecting to login page
Route::get('/admin-login','AdminLoginController@index')->name('admin-login'); 

// Redirecting to Admin Profile Page
Route::get('/admin-profile','AdminProfileController@index')->name('admin-profile'); 

// Calling Login function
Route::post('admin-login-result','AdminLoginController@login')->name('admin-log'); 

// Calling Function to Update Profile
Route::post('admin-edit-profile','AdminEditController@updateProfile')
         ->name('admin-edit-profile'); 

// Redirecting to Profile Edit page
Route::get('/admin-edit-profile','AdminEditController@index')->name('admin-edit'); 
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5

4
推荐指数
1
解决办法
2811
查看次数

从 Laravel 中的数据库获取数据

我想从名为“users”的数据库表中获取数据并在表中显示输出。

我写了下面的代码,但它不起作用。

我正在使用 Laravel 5.5

@extends('layouts.app')


@section('content')

<div class="container">

<h2>Admin Panel</h2>

<p>Data of the Registered Users.</p> 

<table class="table table-bordered">

<thead>

<tr>

<th>Id</th>

<th>Name</th>

<th>Email</th>

</tr>

</thead>

<tbody>

$users = DB::table('users')->select('id','name','email')->get();

@foreach($users as $value)

<tr>

<td>{{ $value->id }}</td>

<td>{{ $value->name }}</td>

<td>{{ $value->email }}</td>

</tr>

@endforeach

</tbody>

</table>

</div>


@endsection
Run Code Online (Sandbox Code Playgroud)

错误:未定义变量:用户

php mysql laravel laravel-5

1
推荐指数
1
解决办法
4万
查看次数

标签 统计

laravel ×3

laravel-5 ×3

php ×2

mysql ×1