T
T
TrixieBek2021-11-22 08:00:25
Laravel
TrixieBek, 2021-11-22 08:00:25

How to fix error 500 in Laravel?

Good afternoon,

Maybe I have a stupid question, but I do not work with Laravel.

I'm trying to create a new page,

1.Created in httpdocs/app/Http/Requests

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;

class Student21Request extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        // only allow updates if the user is logged in
        return backpack_auth()->check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'fio' => 'required|min:5|max:255',
            'image' => 'required',
            'title' => 'required|min:5|max:255'
        ];
    }

    /**
     * Get the validation attributes that apply to the request.
     *
     * @return array
     */
    public function attributes()
    {
        return [
            //
        ];
    }

    /**
     * Get the validation messages that apply to the request.
     *
     * @return array
     */
    public function messages()
    {
        return [
            //
        ];
    }
}


2. in App/models

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;

class Student21 extends Model
{
    use CrudTrait;

    /*
    |--------------------------------------------------------------------------
    | GLOBAL VARIABLES
    |--------------------------------------------------------------------------
    */

    protected $table = 'students21';
    protected $primaryKey = 'id';
    public $timestamps = true;
    protected $guarded = ['id'];
    protected $fillable = [
        'fio',
        'image',
        'title',
        'block1',
        'block2',
        'block3',
        'block4',
        'block5',
        'block6',
        'text_ru',
        'text_kz',
    ];
    // protected $hidden = [];
    // protected $dates = [];

    /*
    |--------------------------------------------------------------------------
    | FUNCTIONS
    |--------------------------------------------------------------------------
    */

    /*
    |--------------------------------------------------------------------------
    | RELATIONS
    |--------------------------------------------------------------------------
    */

    /*
    |--------------------------------------------------------------------------
    | SCOPES
    |--------------------------------------------------------------------------
    */

    /*
    |--------------------------------------------------------------------------
    | ACCESORS
    |--------------------------------------------------------------------------
    */

    /*
    |--------------------------------------------------------------------------
    | MUTATORS
    |--------------------------------------------------------------------------
    */
}


3. Created in /routes/web

Route::get('/national-students21', '[email protected]')->name('national-students21');
    Route::get('/national-students21/{id}', '[email protected]')->name('national-student21');


4.Created a national-students21.blade.php file in resources/views

@extends('layouts.page')

@section('content')

<div class="independent-judges-wrapper indep-judges-page national-finalists">
  <div class="content-title">
    <h1>Финалисты Национальной Премии «Учитель Будущего 2021»</h1>
  </div>
  <div class="indep-judges-wrap">
    @if($students21)
      @foreach($students21 as $student21)
      <div class="indep-judges-item">
        <div class="indep-judges-photo">
          <img src="/{{$student21->image}}">
        </div>
        <a href="{{route('national-student21',['id' => $student21->id])}}"></a>
        <div class="indep-judges-info">
          <h2>{{$student21->fio}}</h2>
          <p>{{$student21->title}}</p>
        </div>
      </div>
      @endforeach
    @endif
  </div>
</div>
  
@endsection


5.Created a national-student21.blade.php file in resources/views

@extends('layouts.page')

@section('content')

@if($student21)
<div class="finalist-info">
  <div class="finalist-info-main">
    <div class="finalist-info-main-photo indep-judges-photo">
      <img src="/{{$student21->image}}">
    </div>
    <div class="finalist-info-main-text">
      <h2>{{$student21->fio}}</h2>
      <p>{{$student21->title}}</p>
    </div>
  </div>
  <div class="finalist-info-block">
    <div class="fi-block-item-wrap">
      <div class="fi-block-item">
        <p>{!!$student21->block1!!}</p>
      </div>
      <div>
        <p>{!!$student21->block2!!}</p>
      </div>
      <div class="fi-block-item">
        <p>{!!$student21->block3!!}</p>
      </div>
    </div>
    <div class="fi-block-item-wrap">
      <div>
        <p>{!!$student21->block4!!}</p>
      </div>
      <div class="fi-block-item">
        <p>{!!$student21->block5!!}</p>
      </div>
      <div>
        <p>{!!$student21->block6!!}</p>
      </div>
    </div>
  </div>
  <div class="news-show-text">
    @if(app()->getLocale() == 'ru')
      <p>{!!$student21->text_ru!!}</p>                   
    @else
      <p>{!!$student21->text_kz!!}</p>
    @endif
  </div>
</div>
@endif

@endsection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-11-22
@TrixieBek

You provided all the code in the question, except for the one that is really needed - PageController.

Method App\Http\Controllers\PageController::national-students21 does not exist
national-students21This error translates as " class method App\Http\Controllers\PageControllerdoes not exist. Actually, it cannot exist with that name, this is a syntax error.
Read the documentation: https://laravel.com/docs/8.x/controllers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question