Laravel 8: Attempt to read property "id" on null - laravel

I am facing this error 'Attempt to read property "id" on null' in Laravel 8. It was working fine before but in my view I changed $user->id to $user->profile->id and now this is happening. I am logged in the app and I have changed my route accordingly to match profile id, I have also tried clearing cache etc.
Here is my Code:
User Model:
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* #var string[]
*/
// protected $fillable = [
// 'name',
// 'email',
// 'password',
// ];
protected $table = 'users';
protected $guarded = [];
/**
* The attributes that should be hidden for serialization.
*
* #var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
public function posts ()
{
return $this->hasMany(Post::class);
}
public function profile()
{
return $this->hasOne(Profile::class);
}
}
Profile Model:
class Profile extends Model
{
use HasFactory;
protected $table = 'profiles';
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class);
}
}
ProfilesController:
class ProfilesController extends Controller
{
public function show(User $user)
{
return view ('profiles.index', compact('user'));
}
public function edit(User $user)
{
return view ('profiles.index', compact('user'));
}
}
Route:
Route::get('profile/{profile}', [ProfilesController::class, 'show'])->middleware('auth');
Route::get('profile/{profile}/edit', [ProfilesController::class, 'edit'])->middleware('auth');
View:
<x-layout>
<section class="py-8 max-w-4xl mx-auto">
<h1 class="text-lg font-bold mb-8 pb-2 border-b">
#if ($user->id == auth()->user()->id)
Hello {{ $user->name }}, welcome to your profile.
#else
{{ $user->name }}'s Profile.
#endif
</h1>
<div class="flex">
<aside class="w-48 flex-shrink-0">
<h4 class="font-semibold mb-4">
Navigation
</h4>
<ul style="max-width: 75%">
<li>
View Profile
</li>
<li>
#if ($user->id == auth()->user()->id)
Edit Profile
#endif
</li>
</ul>
</aside>
<main class="flex-1">
<x-panel>
<div class="flex flex-col">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<div class="flex flex-row grid-cols-12">
<div class="flex flex-col col-span-4 row-span-full justify-items-start flex-grow-0 flex-shrink-0 grid-cols-4">
<div class="flex flex-row">
<img src="http://i.pravatar.cc/60?u={{ $user->profile->id }}" alt="" width="" height="" class="rounded-full h-24 w-24 flex m-2">
</div>
</div>
<div class="flex flex-col col-span-8 justify-right grid-cols-8 text-sm">
<div class="flex flex-row">
<div class="flex flex-col col-span-2 font-semibold">
<div class="pt-3">Name:</div>
<div class="pt-3">Email:</div>
<div class="pt-3">About:</div>
</div>
<div class="flex flex-col col-span-10">
<div class="pt-3 pl-4 text-justify">{{ $user->profile->name }}</div>
<div class="pt-3 pl-4 text-justify">{{ $user->profile->email }}</div>
<div class="pt-3 pl-4 text-justify"><p>{{ $user->profile->description }}</p></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</x-panel>
</main>
</div>
</section>

I think the problem is that you are passing a Profile model as indicated by your routes, but the method is looking for a User model.
Show and Edit have a User Model as a parameter. If you pass the Profile id, the method is gonna find the User model by id but with the id of the Profile model and not the user_id of the Profile model.
You will need to change the methods to:
public function show(Profile $profile)
{
$user = $profile->user;
return view ('profiles.index', compact('user'));
}
public function edit(Profile $profile)
{
$user = $profile->user;
return view ('profiles.index', compact('user'));
}
With this code the Profile model is found and via the relationship the User is obtained and passed to the view.

public function edit($id)
{
$table = Table::find($id);
return view('tables.edit', compact('table'));
}
public function update(Request $request, $id)
{
$table = Table::find($id);
$table->update($request->all());
return redirect('/tables');
}

Related

Is there any way to get an id in a create method in laravel

I am trying to pass a foreign directly to my create method
In the project I am working on, I have two different users. The first one is a farm who can create an animal
The second one is the clinic who can attach to an animal some clinic details showing if the animal was vaccinated or not. In my clinic details table, I have the animal as a foreign key but I do not know how I will pass that key to the create method
Here is my Clinic controller
<?php
namespace App\Http\Controllers;
use App\Animal;
use App\Clinic;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ClinicController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$user = Auth::user();
$animal = Animal::all();
return view('clinic.index', compact('user', 'animal'));
}
/**
* Show the form for creating a new resource.
*
* #param $id
* #return void
*/
public function create($id)
{
$user = Auth::user();
$animal = Animal::query()->findOrFail($id);
$clinic = new Clinic();
return view('clinic/create', compact('user', 'animal', 'clinic'));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$animal = Animal::query()->findOrFail($id);
return view('clinic.show', compact('animal'));
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
My clinic index.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header"><h3>Clinic Details Dashboard</h3></div>
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
You are logged in! {{ $user->name}}
<hr>
<center><h3>Animals</h3></center>
<hr>
#foreach($animal as $animal)
<div class="row">
<div class="col-2">{{ $animal->id }}</div>
<div class="col-4">{{ $animal->type->category }}</div>
<div class="col-2">{{ $animal->user->name }}</div>
<div class="col-4">{{ $animal->created_at }}</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
</div>
#endsection
my clinic show.blade.php
This is where I would like to pass the animal id to the create method but I do not know how.
Even my button link is not going to the create view
#extends('layouts.app')
#section('title', 'Details for animal ')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<center><h3>Details for the animal</h3></center>
</div>
<div class="card-body">
<div class="col-12">
<p><strong>Id: </strong>{{ $animal->id }}</p>
<p><strong>Animal: </strong>{{ $animal->type->category }}</p>
<p><strong>Farm: </strong>{{ $animal->user->name }}</p>
<p><strong>Gender: </strong>{{ $animal->gender }}</p>
<p><strong>Place Of Birth: </strong>{{ $animal->placeOfBirth }}</p>
<p><strong>Date: </strong>{{ $animal->created_at }}</p>
</div>
<div class="col-md-8 offset-md-4">
<a href="create">
<button type="button" class="btn btn-primary">
Attach Clinic Detail
</button>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
clinic create.blade.php
This view is still somehow empty
#extends('layouts.app')
#section('title', 'Add Clinical Details')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">New Animal</div>
<div class="card-body">
<form action="{{ url('clinic') }}" method="POST">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
You could simply add a parameter to your method like this:
public function create($id, $foreignKeyId) {
// ... to something
}
For that you would need to pass id as a hidden input.
You could also try to create a relation, that way you do not need to add the foreignKey as a parameter. You could simply access the foreign_key using the specified ORM Model.
You can use insertGetId() method for retrieving last created id after store method.
https://laravel.com/api/5.0/Illuminate/Database/Query/Builder.html#method_insertGetId
$id = DB::table('posts')->insertGetId(
array('title' => 'my post title', 'body' => 'my post body')
);

How do I deal with controller resource in laravel

I am using the resource tool for my controller and my route but the store method appears not to work. Could you highlight what I did wrong. Is the controller name needs to be the same as the model one? I am confuse
FarmController
<?php
namespace App\Http\Controllers;
use App\Animal;
use Auth;
use Illuminate\Http\Request;
class FarmController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$animal = Animal::all();
return view('farms.index', compact('animal'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$user = Auth::user();
$animal = new Animal();
return view('farms.create', compact('user', 'animal'));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store()
{
Animal::create($this->validateRequest());
return redirect('farms.show');
}
private function validateRequest()
{
return request()->validate([
'dateOfBirth' => 'required|date',
'placeOfBirth' => 'required',
'gender' => 'required',
'user_id' => 'required',
]);
}
Animal.php (controller)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Animal extends Model
{
protected $guarded = [];
public function user(){
return $this->belongsTo(User::class);
}}
animals (table)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnimalsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('animals', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->index();
$table->date('dateOfBirth');
$table->string('gender');
$table->string('placeOfBirth');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('animals');
}
}
create.blade.php
#extends('layouts.app')
#section('title', 'Add Animal')
#section('content')
<div class="row">
<div class="col-12">
<h1>Farm</h1>
</div>
</div>
<h3>Welcome {{ $user->name }} Please Add an animal</h3>
<div class="row">
<div class="col-12">
<form action="{{ url('farms') }}" method="POST">
<div class="form-group">
<label for="dateOfBirth">Date Of Birth: </label>
<input type="date" name="dateOfBirth" class="form-control" placeholder="dd/mm/yyyy">
</div>
<div class="pb-5">
{{ $errors->first('dateOfBirth') }}
</div>
<div class="form-group">
<label for="placeOfBirth">Place Of Birth</label>
<input type="text" name="placeOfBirth" class="form-control">
</div>
<div class="pb-5">
{{ $errors->first('placeOfBirth') }}
</div>
<div class="form-group">
<label for="gender">Gender: </label>
<select name="gender" class="form-control">
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</div>
<div class="form-group">
<label for="user">User</label>
<select class="form-control" name="user">
<option value="{{ $user->id }}" name="user">{{ $user->name }}</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Add Farm</button>
#csrf
</form>
</div>
</div>
#endsection
web.php (routes)
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::middleware('admin')->group(function () {
// All your admin routes go here.
Route::resource('/admin', 'AdminController');
});
Route::middleware('farms')->group(function () {
// All your admin routes go here.
Route::resource('/farms', 'FarmController');
});
When I am submitting the form, it seems like it just refreshes the page and do not add anything in my table. I have been stuck on this in two entire days. any help is welcome
In the validateRequest function you have
'user_id' => 'required',
But your form in the view has no field named user_id
The select element is named user
<select class="form-control" name="user">
<option value="{{ $user->id }}" name="user">{{ $user->name }}</option>
</select>
Change one of them so they can match, I guess that the page refresh is just failed validation
You may want to check for any validation error in your view to find out what's wrong as per the docs
For example
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
Hope this helps
Just change your form action then it hit in correct mehtod. Here is the action for your form
{{route('farms.store')}}

Can't update Laravel database (Model, View, Controller)

I'm currently working with Laravel. I'm a novice and still trying to get used to the platform. I want to update my database based on form input but it's not working. I've tried updating models, views, and controllers and can't seem to get the database to update with input values.
My view:
<div class="form-group row">
<label class="col-xs-2 col-form-label">Expiration Date</label>
<div class="col-xs-10">
<input class="form-control" type="date" value="{{ $Document->expires_at }}" name="expires_at" placeholder="Expiration Date">
</div>
</div></form>
<embed src="{{ asset('storage/'.$Document->url) }}" width="100%" height="100%" />
<div class="row">
<div class="col-xs-6">
<form action="{{ route('admin.provider.document.update', [$Document->provider->id, $Document->id]) }}" method="POST">
{{ csrf_field() }}
{{ method_field('PUT') }}
<button class="btn btn-block btn-primary" type="submit">Approve</button>
</form>
</div></form>
My model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class ProviderDocument extends Model
{
protected $table = 'provider_documents';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'provider_id',
'document_id',
'url',
'unique_id',
'status',
'expires_at',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
];
/**
* The services that belong to the user.
*/
public function provider()
{
return $this->belongsTo('App\Provider');
}
/**
* The services that belong to the user.
*/
public function document()
{
return $this->belongsTo('App\Document');
}
}
My controller:
public function update(Request $request, $provider, $id)
{
if(Setting::get('demo_mode', 0) == 1) {
return back()->with('flash_error', 'Disabled for demo purposes! Please contact us at info#appoets.com');
}
try {
$Document = ProviderDocument::where('provider_id', $provider)
->where('id', $id)
->firstOrFail();
$Document->update(['status' => 'ACTIVE']);
$Document->expires_at = $request['expires_at'];
$Document->save();
return redirect()->route('admin.provider.document.index', $provider)->with('flash_success', 'Provider document has been approved.');
}
catch (ModelNotFoundException $e) {
return redirect()->route('admin.provider.document.index', $provider)->with('flash_error', 'Provider not found!');
}
}
The database stays blank with no errors. If I manually put it in the database directly, then go to the form and update, it's deleted. Please help.
Thanks to the input of ##LimKeanPhang above, below is the end result. I didn't have to change the model or controller. Just the view. Worked like a charm.
<form class="form-horizontal" action="{{ route('admin.provider.document.update', [$Document->provider->id, $Document->id]) }}" method="POST">{{csrf_field()}}
<input type="hidden" name="_method" value="PATCH">
<div class="form-group row">
<label class="col-xs-2 col-form-label">Expiration Date</label>
<div class="col-xs-10">
<input class="form-control" type="date" value="{{ $Document->expires_at }}" name="expires_at" placeholder="Expiration Date">
</div>
</div>
<embed src="{{ asset('storage/'.$Document->url) }}" width="100%" height="100%" />
<div class="row">
<div class="col-xs-6">
<button class="btn btn-block btn-primary" type="submit">Approve</button>
</div>
</div>
</form>
Why don't you get the get the document by id only as follows ? Please try the following code. It should work.
The controller update function.
public function update(Request $request, $provider, $id)
{
if (Setting::get('demo_mode', 0) == 1) {
return back()->with('flash_error', 'Disabled for demo purposes! Please contact us at info#appoets.com');
}
try {
$Document = ProviderDocument::find($id);
$Document->status = 'ACTIVE';
$Document->expires_at = $request['expires_at'];
$Document->save();
return redirect()->route('admin.provider.document.index', $provider)->with('flash_success',
'Provider document has been approved.');
} catch (ModelNotFoundException $e) {
return redirect()->route('admin.provider.document.index', $provider)->with('flash_error',
'Provider not found!');
}
}

How to redirect on reference after admin login

I have to redirect the admin to /admin/reference instead of /admin/index.
I have changed the LoginController,protected $redirectTo = '/admin/reference';.t The same with RegisterController, the same with the VerificationController and the RedirectIfAuthenticated but still no redirection.
LoginController:
protected $redirectTo = '/admin/reference';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
RegisterController:
protected $redirectTo = '/admin/reference';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest');
}
VerificationController:
protected $redirectTo = '/admin/reference';
AdminController:
public function index()
{
return view('admin.index');
}
Authenticate Middleware:
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
RedirectIfAuthenthicated:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/admin/reference');
}
return $next($request);
}
index.blade.php:
This is what is currently shows
#extends('admin.layouts.app')
#section('content')
Willkommen!
#endsection
admin.reference.index:This is what i want it to show
#extends('admin.layouts.app')
#section('title', '| Übersicht Referenzen')
#section('content')
<div class="row justify-content-center">
<div class="col-12">
<div class="panel panel-default">
<div class="panel-heading"><h3>Referenzen</h3></div>
<div class="panel-heading">Seite {{ $references->currentPage() }} von {{ $references->lastPage() }}</div>
<table class="table table-bordered table-striped">
<tr>
<th>Name</th>
<th>Bilder</th>
<th>Priorität</th>
<th>Aktionen</th>
</tr>
#foreach ($references as $reference)
<tr>
<td width="65%">
<a href="{{ route('admin.reference.edit', $reference->id ) }}"><b>{{ $reference->title }}</b>
</a><br>
</td>
<td>
#if(!count($reference->images))<span style="color:#ff0000;font-weight:700;">0</span>#else{{ count($reference->images) }}#endif
</td>
<td>
{{ $reference->priority }}
</td>
<td>
<a href="{{ route('admin.reference.edit', $reference->id) }}" class="btn btn-info pull-left"
style="margin-right: 3px; display: inline-block;">Edit</a>
<div style="display: inline-block;">
{!! Form::open(['method' => 'DELETE', 'route' => ['admin.reference.destroy', $reference->id], 'data-item-id' => $reference->id ]) !!}
{!! Form::submit('Löschen', ['class' => 'btn btn-danger delete-submit','data-item-id' => $reference->id]) !!}
{!! Form::close() !!}
</div>
</td>
</tr>
#endforeach
</table>
</div>
<div class="text-center">
{!! $references->links() !!}
</div>
</div>
</div>
#endsection
I expect after the login to be redirected to /admin/reference instead of /admin/index.
I'm working on laravel 5.5 but I think this would help you. Try adding this to your login controller
protected function authenticated(Request $request, $user)
{
if ( $user->isAdmin() ) {// check role
return redirect('/admin/reference');;
}
return redirect('/anywhere');
}
protected function authenticated()
{
if ( Auth::user() ) {
return redirect('/admin/reference');
}
return redirect('/');
}
added a protected function into my LoginController and it worked.

Cant Display my Reply under the Comment Laravel 5.7

I can't display my reply under each comment. Here is my code...
Comment model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
public function commentable()
{
return $this->morphTo();
}
public function user()
{
return $this->belongsTo('App\User');
}
public function comments()
{
return $this->morphMany('App\Comment', 'commentable');
}
}
Post model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable = [
'user_id', 'topic', 'body', 'category',
];
public function user()
{
return $this->belongsTo('App\User');
}
public function comments()
{
return $this->morphMany('App\Comment', 'commentable');
}
}
Comment controller
<?php
namespace App\Http\Controllers;
use App\Comment;
use App\Post;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class CommentController extends Controller
{
public function store(Request $request, $post)
{
$comment = new Comment;
$comment->body = $request->body;
$comment->user_id = Auth::user()->id;
$post = Post::find($post);
$post->comments()->save($comment);
return back();
}
public function replyStore(Request $request, $comment)
{
$comment = new Comment;
$comment->body = $request->body;
$comment->user_id = Auth::user()->id;
$comment = Comment::find($comment);
$comment->comments()->save($comment);
return back();
}
}
Routes
Route::post('/comment/store/{post}', 'CommentController#store')->name('comment.add');
Route::post('/reply/store/{commentid}', 'CommentController#replyStore')->name('reply.add');
View
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<div class="card">
<div class="card-header">{{$post->topic}}
Create New Post
</div>
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<h3>{{$post->topic}}</h3>
<p>{{$post->body}}</p>
</div>
</div>
<form action="/comment/store/{{$post->id}}" method="post" class="mt-3">
#csrf
<div class="form-group">
<label for="">Comment :</label>
<textarea class="form-control" name="body" id="" rows="3"></textarea>
<br>
<input type="submit" value="Comment" class="btn btn-secondary">
</div>
</form>
<div class="row mt-5">
<div class="col-md-10 mx-auto">
<h6 style="border-bottom:1px solid #ccc;">Recent Comments</h6>
#foreach($post->comments as $comment)
<div class="col-md-12 bg-white shadow mt-3" style="padding:10px; border-radius:5px;">
<h4>{{$comment->user->name}}</h4>
<p>{{$comment->body}}</p>
<button type="submit" class="btn btn-link" onclick="toggleReply({{$comment->id}})">
Reply
</button>
<div class="row">
<div class="col-md-11 ml-auto">
{{-- #forelse ($replies as $repl)
<p>{{$repl->body}}</p>
#empty
#endforelse --}}
</div>
</div>
</div>
<form action="/reply/store/{{$comment->id}}" method="post"
class="mt-3 reply-form-{{$comment->id}} reply d-none">
#csrf
<div class="form-group">
<textarea class="form-control" name="body" id="" rows="3"></textarea>
<br>
<input type="submit" value="Reply" class="btn btn-secondary">
</div>
</form>
#endforeach
</div>
</div>
</div>
</div>
</div>
#endsection
#section('js')
<script>
function toggleReply(commentId) {
$('.reply-form-' + commentId).toggleClass('d-none');
}
</script>
#endsection
I have created the normal table with parent_id but I don't know how to display the replies for each comment. Please, anyone who can help me with this - I am stranded here and the error coming from the second controller function which is replystore() saying it doesn't recognize the comments() method. Please help me out to display the reply.

Resources