0
    
           // web.php
           Route::get('article', 'IndexController@article')->name('article');
    
    // Сontoller  IndexController.php
        protected $message;
        protected $header;
        public function __construct() {
           $this->header = 'This is for site.blade.php Hello World!!!';
           $this->message = 'This is for site.blade.php A simple primary alert—check it out!';
        }
           public function article() {
                $data = \App\Article::all();
                return view('rat-page')->with(['message' => $this->message,
                                               'header' => $this->header,
                                               'data' => $data]);
    
        }
    
    // model Article.php
    
    namespace App;
    use Illuminate\Database\Eloquent\Model;
    class Article extends Model
    {
        //
    }

    // migration 2019_08_28_110014_create_articles_table.php
    
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;
    
    class CreateArticlesTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('articles', function (Blueprint $table) {
                $table->increments('id');
                $table->text('title');
                $table->text('text');
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('articles');
        }
    }
    
    
    
    
           // rat-page.blade.php 
        @extends('layouts.site')
        @foreach($data as $pagedata)
         <a class="btn btn-primary" href="{{ route('index') }}" role="button"> back </a>
         <div class="alert alert-warning" role="alert">
         {{ $pagedata->title }}
         </div>
        @endforeach
        @endsection
    
    
           // site.blade.php 
        <!doctype html>
        <html lang="en">
            <head>
                <meta charset="utf-8">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
            </head>
            <body>
 <div class="alert alert-primary" role="alert">
   {{$message}}
 </div>
 <div class="alert alert-success" role="alert">
    {{$header}}
 </div>
        @yield('content')
            </body>
        </html>
    
    
    
3
  • Приложите к сообщению то, что есть в модели и таблице (миграция) 30 авг 2019 в 10:44
  • покажите связи в модели. И почему @foreach($rat as $rats) и т.д. Вы же сами в контроллере пишете $rats = \App\Rat::all(), а потом резко всё перекручиваете...
    – n.osennij
    31 авг 2019 в 12:29
  • Все заново сделал. Проверьте пожалуйста. 2 сен 2019 в 12:36

0

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Посмотрите другие вопросы с метками или задайте свой вопрос.