please I don't know what else to be done. I created a resource controller and all was ok the create.blade was accessible and working fine, in fact, was saving to the database. even the index page was working before when it was just common HTML, but immediately I inserted the PHP details it starts loading server error 500. please see below:
My index.blade
<div class="col-md-6" style="float:right">
<a href="{{ route('paymentdetails.create') }}" class="btn btn-primary btn-rounded float-right">
<i class="fas fa-plus mr-2"></i>
#lang('Add Paymentdetails')
</a>
</div>
<div class="table-responsive" id="users-table-wrapper">
<table class="table table-borderless table-striped">
<thead>
<tr>
<th class="min-width-80">#lang('Username')</th>
<th class="min-width-150">#lang('Amountpaid')</th>
<th class="min-width-100">#lang('Description')</th>
<th class="min-width-80">#lang('Created_at')</th>
<th class="min-width-80">#lang('Updated_at')</th>
<th class="text-center min-width-150">#lang('Action')</th>
</tr>
</thead>
<tbody>
#if (count($paymentdetails))
#foreach ($paymentdetails as $paymentdetail)
<tr>
<td class="align-middle">
<a href="{{ route('paymentdetails.show', $paymentdetail) }}">
{{ $paymentdetail->username }}
</a>
</td>
<td class="align-middle">{{ $paymentdetail->amountpaid }}</td>
<td class="align-middle">{{ $paymentdetail->description }}</td>
<td class="align-middle">{{ $paymentdetail->created_at }}</td>
<td class="align-middle">{{ $paymentdetail->updated_at }}</td>
<td class="text-center align-middle">
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
<a href="{{ route('paymentdetails.show', $paymentdetail) }}" class="dropdown-item text-gray-500">
<i class="fas fa-eye mr-2"></i>
#lang('View Paymentdetails')
</a>
</div>
<a href="{{ route('paymentdetails.edit', $paymentdetail) }}"
class="btn btn-icon edit"
title="#lang('Edit Paymentdetail')"
data-toggle="tooltip" data-placement="top">
<i class="fas fa-edit"></i>
</a>
<a href="{{ route('paymentdetails.destroy', $paymentdetail) }}"
class="btn btn-icon"
title="#lang('Delete Paymentdetail')"
data-toggle="tooltip"
data-placement="top"
data-method="DELETE"
data-confirm-title="#lang('Please Confirm')"
data-confirm-text="#lang('Are you sure that you want to delete this user?')"
data-confirm-delete="#lang('Yes, delete him!')">
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
#endforeach
#else
<tr>
<td colspan="7"><em>#lang('No records found.')</em></td>
</tr>
#endif
</tbody>
</table>
</div>
</div>
</div>
My controller from web
<?php
namespace Vanguard\Http\Controllers\Web;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Vanguard\Http\Controllers\Controller;
Use Vanguard\Paymentdetails;
class PaymentdetailsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
// dd("am here");
return view('/paymentdetails.index');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('/paymentdetails/create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'username'=>'required',
'amountpaid'=>'required',
'description'=>'required',
]);
$paymentdetails = new Paymentdetails;
$paymentdetails->username = $request-> input('username');
$paymentdetails->amountpaid = $request-> input('amountpaid');
$paymentdetails->description = $request-> input('description');
$paymentdetails->save();
return redirect()->route('paymentdetails.index')
->withSuccess(__('Paymentdetails created successfully.'));
// if($saveFlag){
// return redirect()->back();
// }
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$paymentdetails = Paymentdetails::find($id);
//dd($paymentdetails);
return view('/paymentdetails/view')->with('paymentdetails',$paymentdetails);
}
My controller from API
<?php
namespace Vanguard\Http\Controllers\Api\Paymentdetails;
use Illuminate\Http\Request;
use Vanguard\Http\Controllers\Api\ApiController;
Use Vanguard\Paymentdetails;
class PaymentdetailsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
// dd("am here");
return view('/paymentdetails.index');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('/paymentdetails/create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'username'=>'required',
'amountpaid'=>'required',
'description'=>'required',
]);
$paymentdetails = new Paymentdetails;
$paymentdetails->username = $request-> input('username');
$paymentdetails->amountpaid = $request-> input('amountpaid');
$paymentdetails->description = $request-> input('description');
$paymentdetails->save();
return redirect()->route('paymentdetails.index')
->withSuccess(__('Paymentdetails created successfully.'));
// if($saveFlag){
// return redirect()->back();
// }
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$paymentdetails = Paymentdetails::find($id);
//dd($paymentdetails);
return view('/paymentdetails/view')->with('paymentdetails',$paymentdetails);
}
my route(web)
/**
* Paymentdetails
*/
Route::resource('/paymentdetails', 'PaymentdetailsController')->middleware('permission:paymentdetails.manage');
Related
i found out that these 2 lines cause the problem, but i don't know how to rewrite them to proceed
<a href="{{ route('categories.edit', $post->category->id ) }}">
{{ $post->category->name }}
</a>
Here is my posts/index.blade.php
#extends('layouts.app')
#section('content')
<div class="d-flex justify-content-end mb-2">
Add Post
</div>
<div class="card card-default">
<div class="card-header">Posts</div>
<div class="card-body">
#if ($posts->count()>0)
<table class="table">
<thead>
<th>Image</th>
<th>Title</th>
<th>Category</th>
<th></th>
<th></th>
<tbody>
#foreach($posts as $post)
<tr>
<td>
<img src="{{ asset('storage/'.$post->image) }}" width="120px" height="60px" alt="">
</td>
<td>
{{ $post->title }}
</td>
<td>
<a href="{{ route('categories.edit', $post->category->id ) }}">
{{ $post->category->name }}
</a>
</td>
#if($post->trashed())
<td>
<form action="{{ route('restore-posts', ['post' => $post['id']]) }}" method="POST">
#csrf
#method('PUT')
<button type="submit" class="btn btn-info btn-sm">Restore</button>
</form>
</td>
#else
<td>
Edit
</td>
#endif
<td>
<form action="{{ route('posts.destroy', ['post' => $post['id']]) }}" method="POST">
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger btn-sm">
{{ $post->trashed() ? 'Delete' : 'Trash' }}
</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</thead>
</table>
#else
<h3 class="text-center">
No Posts Yet
</h3>
#endif
</div>
</div>
#endsection
and here is my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\Posts\CreatePostRequest;
use App\Post;
use App\Category;
// use Illuminate\Support\Facades\Storage;
use App\Http\Requests\Posts\UpdatePostRequest;
class PostsController extends Controller
{
public function __construct(){
$this->middleware('verifyCategoriesCount')->only(['create','store']);
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('posts.index')->with('posts', Post::all());
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('posts.create')->with('categories', Category::all());
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$image = $request->image->store('posts');
Post::create([
'title' => $request->title,
'description' => $request->description,
'content' => $request->content,
'image' => $image,
'published_at' => $request->published_at,
'category_id' => $request->category
]);
session()->flash('success', 'Post created succesfully.');
return redirect(route('posts.index'));
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit(Post $post)
{
return view('posts.create')->with('post', $post)->with('categories', Category::all());
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(UpdatePostRequest $request, Post $post)
{
$data = $request->only(['title', 'description', 'published_at', 'content']);
// check if new image
if($request->hasFile('image')){
// upload it
$image = $request->image->store('posts');
// delete old one
$post->deleteImage();
$data['image'] = $image;
}
// update attributes
$post->update($data);
// falsh message
session()->flash('success', 'Post updated succesfully');
// redirect user
return redirect(route('posts.index'));
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$post = Post::withTrashed()->where('id', $id)->firstOrFail();
if($post->trashed()){
$post->deleteImage();
$post->forceDelete();
}else{
$post->delete();
}
session()->flash('success', 'Post deleted succesfully.');
return redirect(route('posts.index'));
}
/**
* Display a list of all trashed posts
*
* #return \Illuminate\Http\Response
*/
public function trashed(){
$trashed = Post::onlyTrashed()->get();
return view('posts.index')->withPosts($trashed);
}
public function restore($id){
$post = Post::withTrashed()->where('id', $id)->firstOrFail();
$post->restore();
session()->flash('success', 'Post restored succesfully');
return redirect()->back();
}
}
Your $post->category is not an object which is why this error is coming.
Try
dd($post->category)
and you'll see what's in it. That will help you to debug the real problem.
First eager load the relation (to prevent N+1 issues) using:
public function index()
{
$posts = Post::with('category')->get();
return view('posts.index')->with('posts', $posts);
}
Then if you still get the error, it might be due to the fact that the post you are trying to view does not have category, so the relation is null. So when you try to get the category id, it throws that exception that null does not have id.
You can simply solve it by checking if there is any category before:
#if($post->category)
<a href="{{ route('categories.edit', $post->category->id ) }}">
{{ $post->category->name }}
</a>
#endif
Use eager loading in your controller before injecting the model to the view.
$post->load('category');
Make sure that each post has a relation with a category.
I received this error while trying to run two-layer loops in order to get a list out of an array:
Undefined property: Illuminate\Pagination\LengthAwarePaginator::$event_parts
I wanted to produce a table where it lists all my events and at the same time there is a column that listed all the attending participants.
Here is the phpmyadmin table:
Here is my EventController:
<?php
namespace App\Http\Controllers;
use App\Models\Event;
use Illuminate\Http\Request;
class EventController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$events = Event::paginate(5);
return view('events.index', compact('events'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$events = Event::all();
return view('events.create', compact('events'));
##return view('events.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'event_name' => 'required',
'event_start' => 'required',
'event_end' => 'required',
'event_category' => 'required',
#'event_part' => 'required'
]);
Event::create($request->all());
return redirect()->route('events.index')
->with('success', 'Event added successfully.');
}
/**
* Display the specified resource.
*
* #param \App\Models\Event $event
* #return \Illuminate\Http\Response
*/
public function show(Event $event)
{
return view('events.show', compact('event'));
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Models\Event $event
* #return \Illuminate\Http\Response
*/
public function edit(Event $event)
{
return view('events.edit', compact('event'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Models\Event $event
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Event $event)
{
$request->validate([
'event_name' => 'required',
'event_start' => 'required',
'event_end' => 'required',
'event_category' => 'required'
]);
$event->update($request->all());
return redirect()->route('events.index')
->with('success', 'Event updated successfully');
}
/**
* Remove the specified resource from storage.
*
* #param \App\Models\Event $event
* #return \Illuminate\Http\Response
*/
public function destroy(Event $event)
{
$event->delete();
return redirect()->route('events.index')
->with('success', 'Event deleted successfully');
}
}
Here is my migration:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEventsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('events', function (Blueprint $table) {
$table->id('event_id');
$table->string('event_name');
$table->datetime('event_start');
$table->datetime('event_end');
$table->string('event_category');
$table->json('event_parts')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('events');
}
}
Here is my index.blade.php:
#extends('layouts.app')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 CRUD </h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('events.create') }}" title="Create a event"> <i class="fas fa-plus-circle"></i>
</a>
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
<table class="table table-bordered table-responsive-lg">
<tr>
<th>No</th>
<th>Event Name</th>
<th>Event Start</th>
<th>Event End</th>
<th>Event Category</th>
<th>Event Participants</th>
<th width="280px">Action</th>
</tr>
#foreach ($events as $event )
<tr>
<td>{{ ++$i }}</td>
<td>{{ $event->event_name }}</td>
<td>{{ $event->event_start }}</td>
<td>{{ $event->event_end }}</td>
<td>{{ $event->event_category }}</td>
<td> #foreach ($events->event_parts as $event_part) {{ $event_part }} #endforeach</td>
<td>
<form action="{{ route('events.destroy', $event->event_id) }}" method="POST">
<a href="{{ route('events.show', $event->event_id) }}" title="show">
<i class="fas fa-eye text-success fa-lg">View</i>
</a>
<a href="{{ route('events.edit', $event->event_id) }}">
<i class="fas fa-edit fa-lg">Edit</i>
</a>
#csrf
#method('DELETE')
<button type="submit" title="delete" style="border: none; background-color:transparent;">
<i class="fas fa-trash fa-lg text-danger">Delete</i>
</button>
</form>
</td>
</tr>
#endforeach
</table>
{!! $events->links() !!}
#endsection
Here is my Cart.blade.php view
<div class="cart">
#if (Cart::count() > 0)
<div class="cart-title">
<h5> There are {{ Cart::count() }} item(s) in your cart! </h5>
</div>
<div class="cart-table">
<table class="table">
#foreach (Cart::content() as $item)
<tbody>
<tr>
<td>
<a href="{{ route('shop.show', $item->model->slug) }}">
<img src="img\mie1.png" alt="" style="width: 7rem;">
</a>
</td>
<td>
<a href="{{ route('shop.show', $item->model->slug) }}">
<t style="font-weight: bold;"> {{ $item->model->name }} </t>
<br>
<d style="color: #acacac;"> varians of this menu the customer chose </d>
</a>
</td>
My web.php
Route::get('/cart', [App\Http\Controllers\CartController::class, 'index'])->name('cart.index');
Route::post('/cart', [App\Http\Controllers\CartController::class, 'store'])->name('cart.store');
Cart controller:
namespace App\Http\Controllers;
use App\Models\Menu;
use Illuminate\Http\Request;
use Gloudemans\Shoppingcart\Facades\Cart;
class CartController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('cart');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
Cart::add($request->id, $request->name, 1, $request->price)
->associate('App\Menu');
return redirect()->route('cart.index')->with('success_message', 'Item was added to your cart!');
}
}
When I run, I get this error:
Error
Class 'App\Menu' not found (View: D:\xampp\htdocs\mieaceh\resources\views\cart.blade.php)
I've tried adding ->associate('App\Models\Menu') in the CartController store but still it won't do anything.
I've solved the problem, it wasn't in the cart.blade.php but the CartController should be like this:
Cart::add($request->id, $request->name, 1, $request->price)
->associate('App\Models\Menu');
After 'php artisan serve' command, the page like 'localhost:8000/biodata' opens and when I click on some link to go to the other page, the current page keeps on loading all the time without giving me any error. When I tried to change the server ports like'localhost:8080/biodata' and then click on the link immediately, the next page opens but the links on the next page doesn't work and the page keeps on loading until I again change the server ports.
I'm practicing with this online version of code from any other link. Here is the code.
index.blade.php:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-10">
<h3>List Biodata Siswa</h3>
</div>
<div class="col-sm-2">
<a class="btn btn-sm btn-success" href="{{ route('biodata.create') }}">Create New Biodata</a>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{$message}}</p>
</div>
#endif
<table class="table table-hover table-sm">
<tr>
<th width = "50px"><b>No.</b></th>
<th width = "300px">Name</th>
<th>Location</th>
<th width = "180px">Action</th>
</tr>
#foreach ($biodatas as $biodata)
<tr>
<td><b>{{++$i}}.</b></td>
<td>{{$biodata->name}}</td>
<td>{{$biodata->location}}</td>
<td>
<form action="{{ route('biodata.destroy', $biodata->id) }}" method="post">
<a class="btn btn-sm btn-success" href="{{route('biodata.show',$biodata->id)}}">Show</a>
<a class="btn btn-sm btn-warning" href="{{route('biodata.edit',$biodata->id)}}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
{!! $biodatas->links() !!}
</div>
#endsection
web.php:
<?php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
route::resource('biodata','BiodataController');
BiodataController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Biodata;
class BiodataController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$biodatas=Biodata::latest()->paginate(5);
return view('biodata.index',compact('biodatas'))
->with('i',(request()->input('page',1)-1)*5);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('biodata.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name'=>'required',
'location'=>'required'
]);
Biodata::create($request->all());
return redirect()->route('biodata.index')
->with('success','new biodata created successfully');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$biodata = Biodata::find($id);
return view('biodata.detail', compact('biodata'));
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$biodata = Biodata::find($id);
return view('biodata.edit', compact('biodata'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$request->validate([
'name' => 'required',
'location' => 'required'
]);
$biodata = Biodata::find($id);
$biodata->name = $request->get('name');
$biodata->location = $request->get('location');
$biodata->save();
return redirect()->route('biodata.index')
->with('success', 'Biodata siswa updated successfully');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$biodata = Biodata::find($id);
$biodata->delete();
return redirect()->route('biodata.index')
->with('success', 'Biodata siswa deleted successfully');
}
}
No error messages but the page keeps on loading.
There is typo error in your web.php file. The last line is
route::resource('biodata','BiodataController');
It should be
Route::resource('biodata','BiodataController');
I have a form in which you submit a "project". One of the field is "created by", but the user does not update this, it gets the name of the authenticated user in that moment and inserts it into the db.
I know how to retrieve the user's name, but the problem is that when I login with another user, then all the name change, because I store the name each time.
This is my project controller
<?php
namespace App\Http\Controllers;
use App\Project;
use App\Client;
use Auth;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('projects.index', [
'project' => Project::all()
]);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
if (Auth::user()->role != 1){
return redirect()->back();
}else{
return view('projects.create',[
'project' => new Project,
'client' => new Client
]);
}
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $r)
{
$validatedData = $r->validate([
'proj_title' => 'required|max:100',
'client_id' => 'required',
'proj_desc' => 'required',
]);
$currentUser = Auth::user()->name;
$r['created_by'] = $currentUser;
$project = Project::create($r->all());
return redirect('/projects')->with('store','');
}
/**
* Display the specified resource.
*
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function show(Project $project)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function edit(Project $project)
{
return view('projects.edit', compact('project'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function update(Request $r, Project $project)
{
$project->update($r->all());
return redirect('/projects')->with('update','');
}
/**
* Remove the specified resource from storage.
*
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function destroy(Project $project)
{
$project->delete();
return redirect('/projects')->with('delete','');
}
}
And this is my index
#section('content')
<div class="row">
<div class="col">
#if (Auth::user()->role == 1)
<a class="btn btn-success" href="/projects/create">Add Project</a>
#endif
</div>
<div class="col"></div>
<div class="col">
#if(session()->has('store'))
<div class="alert alert-success mt-2" role="alert">
<strong>Project created</strong>
</div>
#elseif(session()->has('update'))
<div class="alert alert-success mt-2" role="alert">
<strong>Project updated</strong>
</div>
#elseif(session()->has('delete'))
<div class="alert alert-success mt-2" role="alert">
<strong>Project deleted</strong>
</div>
#endif
</div>
</div>
<br>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Project Id</th>
<th>Title</th>
<th>Description</th>
<th>Client Id</th>
<th>Created by</th>
<th>Created on</th>
#if (Auth::user()->role==1)
<th>Admin</th>
#endif
</tr>
</thead>
<tbody class="">
#foreach ($project as $project)
<tr>
<td>{{$project->proj_id}}</td>
<td>{{$project->proj_title}}</td>
<td>{{$project->proj_desc}}</td>
<td>{{$project->client_id}}</td>
<td>{{$project->Auth::user()->name}}</td>
<td>{{$project->created_at}}</td>
#if (Auth::user()->role==1)
<td>
<div class="dropdown">
<button class="btn btn-danger dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="{{route('projects.edit',$project)}}">Edit</a>
<form method="POST" action="{{route('projects.destroy',$project)}}" onsubmit="return confirm('Are you sure you want to delete this?')">
#method('DELETE')
#csrf
<button class="dropdown-item" type="submit">Delete</button>
</form>
</div>
</div>
</td>
#endif
</tr>
#endforeach
</tbody>
</table>
#endsection
I think your problem is that you are using:
{{ $project->Auth::user()->name }}
instead of
{{ $project->created_by }}