如何从laravel中的锚标签传递数据?

时间:2016-12-14 14:03:49

标签: php laravel laravel-5.2

我目前在提交以下方法的laravel中有一个表单:

public function validateSave() {
        $qualitycheck = new QualityCheck();
        $qualitycheck['site-name'] = Request::input('site-name');
        $qualitycheck['favicon'] = Request::has('favicon');
        $qualitycheck['title'] = Request::has('title');
        $qualitycheck['image-optimization'] = Request::has('image-optimization');
        $qualitycheck->save();
        Session::flash('quality-data', $qualitycheck);
        return redirect('/');
    }

所以我有以下行将数据传递到下一页:

Session::flash('quality-data', $qualitycheck);

但我真正想做的是,当提交表单时,我真的只想在下一页上显示一个链接,其编码如下:

@if(Session::has('quality-data'))
        <a href="">Submited Quality Check</a>
@endif

现在点击链接,我想显示一个视图,其中包含用户在表单中提交的所有数据,我该怎么做? I.E.如何将数据表单从<a>传递到点击<a>时显示的视图?

所以只是为了把事情放在眼里,这就是它现在的运作方式:

STEP-1 :: User submits form , data is flashed to next page.  
STEP-2 :: Data user submits is shown on this page.

我希望它如何工作:

STEP-1 :: User submits form , data is flashed to next page.
STEP-2 :: A link is shown to the user(Only if user clicks on the link we move to the next step).
STEP-3 :: Data user submited in first step is shown on this page.

2 个答案:

答案 0 :(得分:1)

下次编码时,请遵循以下编码惯例。

  1. 首选使用模型的create()功能。
  2. 将您要使用的所有请求数据放在一个变量中(例如$input
  3. 首选使用route('route.name')之类的路由名称,而不是redirection()函数内的字符串。
  4. 请用

    替换您的功能
    public function validateSave() {
      $inputs = [
        'site-name' => request()->get('site_name'),
        'favicon' => request()->has('facvicon'),
        'title' => request()->has('title'),
        'image-optimization' => request()->has('image-optimization')
      ]);
    
      $qualityCheck = QualityCheck::create($inputs);
    
      $flashMessage = '<a href=' . route('quality.check.show', $qualityCheck) . '>Submitted Quality Check</a>'
    
      Session::flash('quality-data', $flashMessage);
    
      return redirect(route('home.index'));
    }
    

    确保路线文件中有类似的内容。

    Route::get('quality-check/{id}', 'QualityCheckController')->name('quality.check.show');
    

    如果有什么不起作用,请告诉我......

答案 1 :(得分:0)

guard let window = UIApplication.shared.keyWindow else {
    return
}

guard let rootViewController = window.rootViewController else {
    return
}

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MainTabbar")
vc.view.frame = rootViewController.view.frame
vc.view.layoutIfNeeded()

UIView.transition(with: window, duration: 0.3, options: .transitionCrossDissolve, animations: {
    window.rootViewController = vc
}, completion: { completed in
    // maybe do something here
})