为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 laravel 在新窗口中打开链接

如何使用 laravel 在新窗口中打开链接

PHP
慕桂英546537 2023-05-26 15:30:39
你好,全球开发人员,请问我需要 laravel 控制器的帮助,我有一个函数可以为 whatsapp msg 生成一个链接,我想在不关闭当前页面的情况下在新选项卡中打开这个链接,请在下面是我的函数代码  public function whatsapp(Request $request){     $whatsapp_log = new WhatsappLog();    $whatsapp_log->telephone = request('tele') ?? request('inp');    $whatsapp_log->calling_no = request('inp');    $whatsapp_log->text = request('check') ? request('check') . '>' . request('txt') : request('txt');    $whatsapp_log->log_by = auth()->user()->name;    $whatsapp_log->save();     $mail = mail::where('id', '=', request()->get('id'))->first();    $mail->status = 0;    $mail->updated_by = auth()->user()->name;    $mail->save();    event(new MailDoneEvent($mail));    if (request('inp') == 'custom') {        $url = "https://wa.me/972" . request('tele') . "?text=" . str_replace(' ', '%20', request('txt')) . str_replace(' ', '%20', request('check'));        return Redirect::away($url);    } else {        $url = "https://wa.me/972" . request('inp') . "?text=" . str_replace(' ', '%20', request('txt')) . str_replace(' ', '%20', request('check'));            , 'success'); return Redirect::away($url);    }    return redirect()->back();}
查看完整描述

1 回答

?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

你可以使用像


public function whatsapp(Request $request)

    $whatsapp_log = new WhatsappLog();

    $whatsapp_log->telephone = request('tele') ?? request('inp');

    $whatsapp_log->calling_no = request('inp');

    $whatsapp_log->text = request('check') ? request('check') . '>' . request('txt') : request('txt');

    $whatsapp_log->log_by = auth()->user()->name;

    $whatsapp_log->save(); 

    $mail = mail::where('id', '=', request()->get('id'))->first();

    $mail->status = 0;

    $mail->updated_by = auth()->user()->name;

    $mail->save();

    event(new MailDoneEvent($mail));

    if (request('inp') == 'custom') {

        $url = "https://wa.me/972" . request('tele') . "?text=" . str_replace(' ', '%20', request('txt')) . str_replace(' ', '%20', request('check'));


    } else {

        $url = "https://wa.me/972" . request('inp') . "?text=" . str_replace(' ', '%20', request('txt')) . str_replace(' ', '%20', request('check'));

            , 'success');

    }


        session()->flash('url', $url);



    return redirect()->back();

}

在你的视图文件中


@if (session()->has('url'))

    <script>

        window.open('{{session()->get('url')}}', "_blank");

    </script>

@endif


查看完整回答
反对 回复 2023-05-26
  • 1 回答
  • 0 关注
  • 211 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信