我在laravel 5.2中遇到错误 当我使用控制器上的 storeMessage函数访问它时
这是我的错误声明:
6p12af76911d23528f6e0ea587ccab13391eacf9.php第37行中的ErrorException: 未定义的变量:thisPage(视图:E:\ xampp \ htdocs \ beasiswa \ resources \ views \ layouts \ partials \ sidebar.blade.php)(视图:E:\ xampp \ htdocs \ beasiswa \ resources \ views \ layouts \ partials \ sidebar.blade.php)(查看:E:\ xampp \ htdocs \ beasiswa \ resources \ views \ layouts \ partials \ sidebar.blade.php)
这是我的代码: 查看代码
<?php $thisPage = "jenisbeasiswa"; ?>
@extends('layouts.app')
@section('htmlheader_title')
Portal Beasiswa
@endsection
@section('contentheader_title')
Broadcast Beasiswa via Telegram Messenger
@endsection
@section('main-content')
<form action="{{ url('/send-message') }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" id="message" class="form-control" placeholder="Enter your query" rows="10"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
@endsection
这是我的控制器代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Telegram\Bot\FileUpload\InputFile;
use Telegram\Bot\Laravel\Facades\Telegram;
class TelegramBotController extends Controller
{
public function updatedActivity()
{
$activity = Telegram::getUpdates();
dd($activity);
}
public function sendMessage()
{
return view('beasiswa.telegram');
}
public function storeMessage(Request $request)
{
$request->validate([
'email' => 'required|email',
'message' => 'required'
]);
$text = "[HEADLINE] Informasi Portal Beasiswa\n"
. "<b>Email Address: </b>\n"
. "$request->email\n"
. "<b>Message: </b>\n"
. $request->message;
Telegram::sendMessage([
'chat_id' => env('TELEGRAM_CHANNEL_ID', ''),
'parse_mode' => 'HTML',
'text' => $text
]);
return redirect()->back();
}
}
答案 0 :(得分:0)
显然sidebar.blade.php
是指$thisPage
变量(在视图代码的顶部声明)。我的猜测是,您将边栏包含在layouts.app
模板中。但是,当您扩展layouts.app
时,$thisPage
变量将首先在边栏中呈现,然后声明才出现在视图代码中。因此,它将在边栏中未定义。
因此,您应该尝试另一种方法。为什么甚至要设置$thisPage
变量?也许您可以从控制器中传递它?