0
votes

I am getting an error in laravel 5.2 when I access it using the storeMessage function on my Controller

This is my ERROR STATEMENT:

ErrorException in 6e12af76911d23528f6e0ea587ccab13391eacf9.php line 37: Undefined variable: thisPage (View: E:\xampp\htdocs\beasiswa\resources\views\layouts\partials\sidebar.blade.php) (View: E:\xampp\htdocs\beasiswa\resources\views\layouts\partials\sidebar.blade.php) (View: E:\xampp\htdocs\beasiswa\resources\views\layouts\partials\sidebar.blade.php)

And this is my code: View Code

<?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

and this is my Controller Code:

<?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();
    }
}
1
Can you share your view code please - Riajul Islam
From Review: Please EDIT your question and post the error as text. Do not post is as a comment to your own question. Thanks! - sɐunıɔןɐqɐp

1 Answers

0
votes

Apparently sidebar.blade.php is referring to the $thisPage variable (which is declared at the top of your view code). My guess is, you are including the sidebar in the layouts.app template. But as you extend your layouts.app the $thisPage variable will get rendered in the sidebar first before the declaration comes in your view code. And thus, it will be undefined in the Sidebar.

So, you should try another approach. Why do you even want to set the $thisPage variable? Maybe you can pass it in from the controller?