I have a dynamic navigation bar, created however it won't show on the dynamic web page.

The current output is:
ErrorException
Undefined variable: navContent (View: C:\Users\Computer
Angel\Documents\blog\resources\views\page\dynamic.blade.php)

The desired output is my dynamic.blade.php where the pageContent is the dynamic page content the user inputted through a form and the dynamic navigation bar in the tags.

This is my dynamic.blade.php:

```
<nav>
    @foreach($navContent as $nav)
    <a href="{!!$nav->navLink!!}">{!!nav-navName!!}</a>
    @endforeach        
    </nav>
    <body>
        {!!$pageContent->pageContent!!}
    </body>

```

This is my NavController.php:

```
    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Nav;
use DB;
use Illuminate\Database\MySqlConnection;
class NavController extends Controller
{
    public function index()
    {
        $navs = Nav::all();
        return view('navManagement', compact('navs'));
    }
    public function create()
    {
        return view('createNav');
    }
    public function store(Request $request)
    {
        $data = request()->validate([
            'navName'            =>  'required',
            'navLink'              =>  'required',
       ]);
        $nav = new Nav([
            'navName'            =>    $request->get('navName'),
            'navLink'              =>    $request->get('navLink'),
        ]);
        $nav->save();
        return redirect('/n');
    }
    public function show($navName)
    {
        $navContent = DB::table('navs')->where('navName',$navName)->first();
        return view('page.dynamic', ['navContent' => $navContent]);
    }
    public function edit($navName)
    {
        $navContent = DB::table('navs')->where('navName',$navName)->first();
        return view('editNav', ['navContent' => $navContent]);
    }
    public function update(Request $request)
    {
        $data = $request->validate([
            'navName' => 'required|exists:navs,navName',
            'navLink' => 'required'
        ]);
        $obj = \App\Nav::where('navName', $request->navName)
            ->update([
                'navLink' => $request->navLink
           ]);
        return redirect('/n');
    }
    public function destroy(Request $request)
    {
        $obj = \App\Nav::where('navName', $request->navName)
        ->delete();
        return redirect('/n');
    }
}

```

This is my PageController.php:

```
<?php

namespace App\Http\Controllers;
use App\Page;
use Illuminate\Http\Request;
use DB;
use Illuminate\Database\MySqlConnection;
class PageController extends Controller
{
    public function index()
    {
        $pages = Page::all();
        return view('pageManagement', compact('pages'));
    }
    public function create()
    {
        //This will load create.blade.php
        return view('createPage');
    }
    public function store(Request $request)
    {
        $data = request()->validate([
            'title'            =>  'required',
            'URI'              =>  'required|min:5|max:10|',
            'pageContent'      =>  'required',
        ]);
        $page = new Page([
            'title'            =>    $request->get('title'),
            'URI'              =>    $request->get('URI'),
            'pageContent'      =>    $request->get('pageContent'),
        ]);
        $page->save();
        return redirect('/p');
    }
    public function show($URI)
    {
        $pageContent = DB::table('pages')->where('URI',$URI)->first();
        return view('page.dynamic', ['pageContent' => $pageContent]);
    }
    public function edit($URI)
    {
        $pageContent = DB::table('pages')->where('URI',$URI)->first();
        return view('editPage', ['pageContent' => $pageContent]);
    }
    public function update(Request $request)
    {
        $data = $request->validate([
            'title' => 'required',
            'URI' => 'required|min:5|max:10|exists:pages,URI',
            'pageContent' => 'required'
        ]);
        $obj = \App\Page::where('URI', $request->URI)
            ->update([
                'title' => $request->title,
                'pageContent' => $request->pageContent
           ]);
        return redirect('/p');
    }
    public function destroy(Request $request)
    {
        $obj = \App\Page::where('URI', $request->URI)
        ->delete();
        return redirect('/p');
    }
}

```

This is my Nav.php:

```
class Nav extends Model
{
    protected $fillable = ['navName', 'navLink'];
}

```

This is my Page.php:

```
class Page extends Model
{
    protected $fillable = ['title', 'URI', 'pageContent'];
}

```

This is my migration for pages:

```
public function up()
    {
        Schema::create('pages', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('URI');
            $table->text('pageContent');
            $table->timestamps();
        });
    }

```

This is my migration for nav:

```
public function up()
    {
        Schema::create('navs', function (Blueprint $table) {
            $table->id();
            $table->string('navName');
            $table->string('navLink');
            $table->timestamps();
        });
    }

```

This is my createNav.blade.php:

```
<form action="/storeNav" method="post">
@csrf
  <label for="navName">Navigation Bar Option Name:</label><br>
  <input type="text" id="navName" name="navName" autocomplete="off" value="{{ old('navName') }}"> 
<br>
  @error('navName') <p style="color: red">{{ $message }}</p> @enderror
  <label for="navLink">Navigation Bar Option Link:</label><br>
  <input type="text" id="navLink" name="navLink" autocomplete="off" value="{{ old('navLink') }}"> 
<br>
  @error('navLink') <p style="color: red">{{ $message }}</p> @enderror
  <input type="submit" value="Submit">
</form>

```

This is my createPage.blade.php:

```
<form action="/storePage" method="post">
@csrf
  <label for="title">Title:</label><br>
  <input type="text" id="title" name="title" autocomplete="off" value="{{ old('title') }}"><br>
  @error('title') <p style="color: red">{{ $message }}</p> @enderror
  <label for="URI">URI:</label><br>
  <input type="text" id="URI" name="URI" autocomplete="off" value="{{ old('URI') }}"><br>
  @error('URI') <p style="color: red">{{ $message }}</p> @enderror
  <label for="pageContent">Page Content:</label><br>
  <textarea id="pageContent" name="pageContent" value="{{ old('pageContent') }}"></textarea>
  @error('pageContent') <p style="color: red">{{ $message }}</p> @enderror
  <input type="submit" value="Submit">
</form>

```

This is my web.php:

```
Route::get('/page/{URI}', 'PageController@show');
Route::get('/page/{URI}/edit', 'PageController@edit');
Route::get('/p', 'PageController@index');
Route::get('/createPage', 'PageController@create');
Route::post('/storePage', 'PageController@store');
Route::patch('/page/{URI}', 'PageController@update');
Route::delete('/page/{URI}', 'PageController@destroy');
Route::get('/nav/{navName}/edit', 'NavController@edit');
Route::get('/n', 'NavController@index');
Route::get('/createNav', 'NavController@create');
Route::post('/storeNav', 'NavController@store');
Route::patch('/nav/{navName}', 'NavController@update');
Route::delete('/nav/{navName}', 'NavController@destroy');

```

Below is my github repository link, if you want to take a look at my full code, or you want to try run the code in your Integrated Development Environment.
<https://github.com/xiaoheixi/blog>

Thanks for reading! :D