页面内动态重定向PHP

时间:2019-01-22 21:56:20

标签: php laravel routes

今天我有一个麻烦的问题要问你。

我正在使用PHP Laravel开发我的小组项目,实际上我们正在结束前端。 在我的想象中,我们的主要“欢迎”页面应如下所示:

Login  |  Register (dinamically changing with id accordion + collapse)

Then if clicked Login - we get Login & Password to Log in
And if clicked Register - we get panel for register into site.

我的问题是-如何进行漂亮的动态更改,因为实际上我有:

<div id="accordion">
    <ul class="nav justify-content-center">
        <div class="card text-center p-3" style="width: 40rem">
            <p>
                <a class="btn btn-primary" data-toggle="collapse" data-target="#collapseLogin" href="#collapseLogin" role="button" aria-expanded="false" aria-controls="collapseLogin">
                    Login
                </a>
                <a class="btn btn-primary" data-toggle="collapse" data-target="#collapseRegister" href="#collapseRegister" role="button" aria-expanded="false" aria-controls="collapseRegister">
                    Register
                </a>
            </p>

            <div class="collapse" id="collapseLogin" aria-labelledby="collapseLogin" data-parent="#accordion">
                <div class="card card-body">
                    <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                </div>
            </div>
            <div class="collapse" id="collapseRegister" aria-labelledby="collapseRegister" data-parent="#accordion">
                <div class="card card-body">
                    <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                </div>
            </div>
        </div>
    </ul>
</div>

...并按href页面重定向。

有人可以帮助我解决这个问题吗?谢谢!

如果要精确说明问题: 更改方式

<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>

获取注册表格(来自register.blade.php),而不链接到该网站。

1 个答案:

答案 0 :(得分:0)

嗨,如果我理解正确,您想用表格替换链接, 如果是这样,那么您可以这样做。

        <div class="collapse" id="collapseLogin" aria-labelledby="collapseLogin" data-parent="#accordion">
            <div class="card card-body">
                @include('auth/login')
            </div>
        </div>

,然后转到resources / views / auth / login.blade.php并进行正确的更改(例如,删除@extends等。只要保留

....
。更简单的解决方案,请尝试

<div class="collapse" id="collapseLogin" aria-labelledby="collapseLogin" data-parent="#accordion">
            <div class="card card-body">

                <form method="POST" action="{{ route('login') }}" aria-label="{{ __('Login') }}">
                    @csrf

                    <div class="form-group row">
                        <label for="email" class="col-sm-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                        <div class="col-md-6">
                            <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>

                            @if ($errors->has('email'))
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $errors->first('email') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>

                            @if ($errors->has('password'))
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $errors->first('password') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group row">
                        <div class="col-md-6 offset-md-4">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>

                                <label class="form-check-label" for="remember">
                                    {{ __('Remember Me') }}
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-0">
                        <div class="col-md-8 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Login') }}
                            </button>

                            <a class="btn btn-link" href="{{ route('password.request') }}">
                                {{ __('Forgot Your Password?') }}
                            </a>
                        </div>
                    </div>
                </form>

            </div>
</div>

对注册执行相同操作