post request not working in laravel livewire - php

hello guys I'm new to laravel and livewire please kindly assist, post request not going through , if i click on the submit nothing is happening, I'm not getting error either, I have added the livewire script in my app.blade.php and it's rendering properly
Post Create form
<div>
<div class="p-4 mx-auto mt-3 bg-gray-100 md:p-8 md:w-4/5 md:mt-0">
<h1 class="mb-3 text-xl font-semibold text-gray-600">New post</h1>
<form wire:submit.prevent="createPost" action="#" class="px-4 py-6 space-y-4">
<div class="overflow-hidden bg-white rounded-md shadow">
<div class="px-4 py-3 space-y-8 sm:p-6">
<div class="grid grid-cols-6 gap-6">
<div class="col-span-6 sm:col-span-3">
<input class="w-full" type="text"
wire:model="post.title" placeholder="Post title" />
</div>
</div>
<div class="flex flex-col">
<textarea id="body" rows="4" wire:model="post.body"
class="border-gray-300 rounded-sm form-textarea">
</textarea>
</div>
</div>
<div class="px-4 py-3 text-right bg-gray-50 sm:px-6">
<button type="submit" class="inline-flex justify-center">
post
</button>
</div>
</div>
</form>
</div>
</div>
this is my post create livewire method
<?php
namespace App\Http\Livewire;
use App\Models\Post;
use Livewire\Component;
use Illuminate\Http\Response;
class PostCreate extends Component
{
public $post;
public $points = 10;
public $energy = 1;
public function increment()
{
$this->points++;
}
protected $rules = [
// 'category' => 'required|integer|exists:categories,id',
'title' => 'required|min:4',
'body' => 'required|min:4',
];
public function createPost()
{
if (auth()->check()) {
$this->validate();
$post = Post::create([
'user_id' => auth()->user()->id,
// 'category_id' => $this->category,
'body' => $this->body,
'title' => $this->title,
]);
$users = auth()->user();
$users->increment('points', 10);
session()->flash('success_message', 'Post was added successfully!');
$this->reset();
return redirect()->route('posts.index');
}
// abort(Response::HTTP_FORBIDDEN);
}
public function render()
{
return view('livewire.post-create');
}
}

There are two thing here to note - you don't initialize $this->post and you don't have the proper validation. You need to check for post.title and post.body, and you also need to display the actual errors.
<?php
namespace App\Http\Livewire;
use App\Models\Post;
use Livewire\Component;
class PostCreate extends Component
{
public $post;
public $points = 10;
public $energy = 1;
public function mount()
{
$this->post = new Post;
$this->post->user_id = auth()->id();
}
public function increment()
{
$this->points++;
}
protected $rules = [
// 'category' => 'required|integer|exists:categories,id',
'post.title' => 'required|min:4',
'post.body' => 'required|min:4',
];
public function createPost()
{
if (auth()->check()) {
$this->validate();
$post = $this->post->save();
auth()
->user()
->increment('points', 10);
session()->flash('success_message', 'Post was added successfully!');
$this->reset();
return redirect()->route('posts.index');
}
// abort(Response::HTTP_FORBIDDEN);
}
public function render()
{
return view('livewire.post-create');
}
}
To display the errors from validation, you can add the following snippet in your blade-file,
#if ($errors->any())
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif

Add lazy to the wire.model:
<input class="w-full" type="text" wire:model.lazy="post.title" placeholder="Post title" />
<textarea id="body" rows="4" wire:model.lazy="post.body" class="border-gray-300 rounded-sm form-textarea"></textarea>

Related

Adding comments and likes to the object laravel 8

I'm writing applications from tutorial for booking tourist objects in laravel 8. I have a problem redirecting to the website after adding a comment and liking the object. When I click "like" or "add comment" it shows me an error below. Any ideas what im doing wrong?
Error:
Not Found
The requested URL was not found on this server.
Apache/2.4.52 (Win64) OpenSSL/1.1.1m PHP/7.4.27 Server at localhost Port 80
My files for likes
Object.blade.php:
#auth
#if( $touristObject->isLiked() )
Odlub ten obiekt
#else
Polub ten obiekt
#endif
#else
<p>Zaloguj się aby polubić obiekt</p>
#endauth
FrontendController:
public function like($likeable_id, $type, Request $request)
{
$this->fR->like($likeable_id, $type, $request);
return redirect()->back();
}
public function unlike($likeable_id, $type, Request $request)
{
$this->fR->unlike($likeable_id, $type, $request);
return redirect()->back();
}
FrontendRepository:
public function like($likeable_id, $type, $request)
{
$likeable = $type::find($likeable_id);
return $likeable->users()->attach($request->user()->id);
}
public function unlike($likeable_id, $type, $request)
{
$likeable = $type::find($likeable_id);
return $likeable->users()->detach($request->user()->id);
}
Model TouristObject:
public function isLiked()
{
return $this->users()->where('user_id',Auth::user()->id)->exists();
}
My files for comments
object.blade.php:
#auth
<a class="btn btn-primary" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Dodaj komentarz
</a>
#else
<p>Zaloguj się aby dodać komentarz</p>
#endauth
<div class="collapse" id="collapseExample">
<div class="well">
<form method="POST" action="{{ route('addComment',['commentable_id'=>$touristObject->id, 'App\TouristObject']) }}" class="form-horizontal">
<fieldset>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Skomentuj</label>
<div class="col-lg-10">
<textarea required name="content" class="form-control" rows="3" id="textArea"></textarea>
<span class="help-block">Dodaj komentarz do tego obiektu</span>
</div>
</div>
FrontendRepository:
public function addComment($commentable_id, $type, $request)
{
$commentable = $type::find($commentable_id);
$comment = new Comment;
$comment->content = $request->input('content');
$comment->rating = $type == 'App\TouristObject' ? $request->input('content') : 0;
$comment->user_id = $request->user()->id;
return $commentable->comments()->save($comment);
}
FrontendGateway:
public function addComment($commentable_id, $type, $request)
{
$this->validate($request, [
'content' => "required|string"
]);
return $this->fR->addComment($commentable_id, $type, $request);
}
Routes:
Route::get('/like/{likeable_id}/{type}','FrontendController#like')->name('like');
Route::get('/unlike/{likeable_id}/{type}','FrontendController#unlike')->name('unlike');
Route::post('/addComment/{commentable_id}/{type}','FrontendController#addComment')->name('addComment');

Method Livewire\Redirector::withInput does not exist. in laravel

I am using live wire and when I try to validate the form it say
Method Livewire\Redirector::withInput does not exist.
and this is my code
Posts.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Post;
class Posts extends Component
{
public $title;
public $content;
public function hydrate(){
$this->validate([
'title' => 'required',
'content' => 'required'
]);
}
public function save(){
$data = [
'title' => $this->title,
'content' => $this->content,
'user_id' => Auth()->user()->id
];
Post::create($data);
$this->cleanVars();
}
private function cleanVars(){
$this->title = null;
$this->content = null;
}
public function render()
{
return view('livewire.posts');
}
}
livewire view
<div>
<label>Title</label>
<input wire:model="title" type="text" class="form-control" />
#error('title')
<p class="text-danger">{{ $message }}</p>
#enderror
<label>Content</label>
<textarea wire:model="content" type="text" class="form-control"></textarea>
#error('content')
<p class="text-danger">{{ $message }}</p>
#enderror
<br />
<button wire:click="save" class="btn btn-primary">Save</button>
</div>
also I putted this view in home.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">{{ __('Dashboard') }}</div>
<div class="card-body">
#livewire('posts')
</div>
</div>
</div>
</div>
</div>
#endsection
Really you need to fix the header of this question, is repeating the same and you're missing something there to the community. I see in your code this and I dislike this use
public function hydrate(){
$this->validate([
'title' => 'required',
'content' => 'required'
]);
}
I mean, this validation running on every hydration isn't a good approach of this. Instead, declare the rules
protected $rules = [// rules here];
//or
public function rules()
{
return [
//rules here
];
}
then you can validate the entries, for example on real-time validation using the validateOnly method inside the updated()
public function updated($propertyName)
{
$this->validateOnly($propertyName, $this->rules());
}
or just use it in the save method
public function save()
{
$this->validate(); // in the protected $rules property
// or
Post::create($this->validate());
}

ArgumentCountError Too few arguments to function App\Http\Controllers\Shop\CartController::addToCart()

So this function is supposed to add the product into a cart, but i've been getting the error
Too few arguments to function
App\Http\Controllers\Shop\CartController::addToCart(), 0 passed in
C:\xampp\htdocs\nerdS\vendor\laravel\framework\src\Illuminate\Routing\Controller.php
on line 54 and exactly 1 expected
I tried changing key words here and there on my controller, but nothing seems to do it. This is the the controller:
<?php
namespace App\Http\Controllers\Shop;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
Use App\Models\Product;
Use App\Models\Order;
class CartController extends Controller {
public function placeOrder() {
if(session('id')){
if(\Cart::count()){
\App\Models\Order::store();
return redirect('shop')->with('status', 'Thank you for buying!');
}
return redirect('cart');
}
session(['place-order-process' => true]);
return redirect('login')->with('status', 'To complete your order, please log in. Not a member yet? Join the club! ');
}
public function deleteCart() {
\Cart::destroy();
return redirect('shop')->with('status', 'The cart is now empty.');
}
public function deleteItem($rowId) {
\Cart::remove($rowId);
return redirect('cart')->with('status', 'The item was deleted.');
}
public function updateCart(Request $request){
\Cart::update($request->rowId, $request->quantity);
$data = [
'cart_count' =>\Cart::count(),
'cart_total' => \Cart::total(),
'product_total' => \Cart::get($request->rowId)->total(),
];
return json_encode($data);
}
public function displayCart() {
\Cart::setGlobalTax(0);
$data['items'] = \Cart::content();
$data['total'] = \Cart::total();
return view('cart.cart', $data);
}
public function addToCartByQty (Request $request){
\App\Models\Product::addToCart($request->id, (int) $request->quantity);
return \Cart::count();
}
public function addToCart ($id){
\App\Models\Product::addToCart($id);
return \Cart::count();
}
}
My model for products:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
class Product extends Model {
public function category() {
return $this->belongsTo('App\Models\Category');
}
public static function deleteProduct($id){
$product = self::findOrFail($id);
Storage::disk('public')->delete($product->image);
self::destroy($id);
}
public static function editProduct($request){
$product = self::findOrFail($request->product);
$product->name = $request->name;
$product->slug = $request->slug;
$product->price = $request->price;
$product->description = $request->description;
$product->category_id = $request->category;
if ($request->image){
Storage::disk('public')->delete($product->image);
$product->image = $request->image->store('images/products', 'public');
}
$product->save();
}
public static function getProductById($id){
return self::finOrFail($id);
}
public static function store($request){
$product = new self();
$product->name = $request->name;
$product->slug = $request->slug;
$product->price = $request->price;
$product->description = $request->description;
$product->category_id = $request->category;
$product->image = $request->image->store('images/products', 'public');
$product->save();
}
public static function getAll(){
return self::orderBy('slug')->get();
}
public static function addToCart($id, $qty = 1){
$product = self::findOrFail($id);
\Cart::add([
'id' => $product->id,
'name' => $product->name,
'qty' => $qty,
'price' => $product->price,
'weight' => 0
]);
}
public static function getProduct($cat, $pro){
$product = self::where('slug', $pro)->firstOrFail();
$product_cat = $product->category->slug;
//retun ($product_cat === $cat) ? $product_cat: false;
abort_if($product_cat !== $cat, 404);
return $product;
}
//use HasFactory;
}
The page view:
#extends('template')
#section('content')
<div class="row">
<div class="col-md-7">
<h1> {{$product->name}} </h1>
<p>{{$product->descriprion}}</p>
<p> Only for: ₪ {{$product->price}}</p>
<form id="add-to-cart" method="post" action="{{url('add-to-cart')}}">
#csrf
<div class="number">
<span class="minus"> - </span>
<input type="text" value="1" readonly/>
<span class="plus"> + </span>
<input type="hidden" value="{{$product->id}}">
<button class="btn btn-primary" type="submit"> Add </button>
</div>
</form>
<div class="col-md-5">
<img src="{{asset('storage/' . $product->image)}}">
</div>
</div>
</div>
#endsection
and my route:
Route::get('add-to-cart/{product_id}', 'App\Http\Controllers\Shop\CartController#addToCart');
You need to pass the $product->id in the form action's url(). That route parameter needs to be there so that it is received in the addToCart method in controller
#extends('template')
#section('content')
<div class="row">
<div class="col-md-7">
<h1> {{$product->name}} </h1>
<p>{{$product->descriprion}}</p>
<p> Only for: ₪ {{$product->price}}</p>
<form id="add-to-cart" method="post" action="{{url('add-to-cart/' . $product->id)}}">
#csrf
<div class="number">
<span class="minus"> - </span>
<input type="text" value="1" readonly/>
<span class="plus"> + </span>
<input type="hidden" value="{{$product->id}}">
<button class="btn btn-primary" type="submit"> Add </button>
</div>
</form>
<div class="col-md-5">
<img src="{{asset('storage/' . $product->image)}}">
</div>
</div>
</div>
#endsection
And you have declared your route as get instead of post. Following restful conventions your route should be declared as a post route
Route::post('add-to-cart/{product_id}', 'App\Http\Controllers\Shop\CartController#addToCart');
There is a mismatch in your route (Route::get('add-to-cart/{product_id}) and the parameter passed in your function addToCart ($id)
Had u provide product_id in route (add-to-cart/{product_id})?
Since you are using a GET route vs POST, you have to change your form method from POST to GET and also pass the id in the action url -
<form id="add-to-cart" method="get" action="{{url('add-to-cart/' . $product->id)}}">
Change your definition of addToCart method in CartController as following.
public function addToCart (Request $request, $id)
{
\App\Models\Product::addToCart($id);
return \Cart::count();
}

Laravel 7 Invalid argument supplied for foreach() when trying to delete post with multiple images

I am running Laravel 7 and have a list of tasks (would be posts if it were a blog) and I need to make sure that when the task is deleted, that all subsequent images are deleted in both the database and in the disc. When I click the delete button, the page throws an error: Invalid argument supplied for foreach().
Unfortunately, this is a vague error and can be caused by a variety of causes. My hopes are that someone can take a look at my code and see if I am missing something. I am relatively new to Laravel so tracking down this issue has been more than a challenge. Than you in advance for helping my work out this issue.
In my Task.php model, I have:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Image;
use Illuminate\Support\Facades\Storage;
class Task extends Model
{
protected $fillable = [
'task_name', 'task_priority', 'task_assigned_to', 'task_assigned_by', 'task_description', 'task_to_be_completed_date', 'task_status',
'task_notes'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function image()
{
// return $this->hasMany('App\Image');
return $this->hasMany(Image::class);
}
public static function boot()
{
parent::boot();
self::deleting(function ($task) {
foreach ($task->images as $image) {
$image->delete();
}
});
}
}
In my Image.php model, I have
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use App\Task;
class Image extends Model
{
protected $fillable = [
'task_id',
'name',
];
protected $uploads = '/task-images/';
public function getFileAttribute($image)
{
return $this->uploads . $image;
}
public function task()
{
// return $this->belongsTo('App\Task', 'task_id');
return $this->belongsTo(Task::class);
}
public static function boot()
{
parent::boot();
self::deleting(function ($image) {
Storage::delete(Storage::path($image->name));
});
}
}
In my TasksController.php, (all code in case something is causing a conflict here) here is what I have:
<?php
namespace App\Http\Controllers;
use App\Task;
use App\Image;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
class TasksController extends Controller
{
public function index()
{
$tasks = Task::orderBy('created_at', 'desc')->paginate(10);
return view('/tasks')->with('tasks', $tasks);
}
public function create()
{
return view('tasks.create');
}
public function store(Request $request)
{
$this->validate($request, [
'task_name' => 'required',
'task_description' => 'required',
]);
// Create Task
$user = Auth::user();
$task = new Task();
$data = $request->all();
$task->user_id = $user->id;
$task = $user->task()->create($data);
if ($request->hasFile('images')) {
$files = $request->file('images');
foreach ($files as $file) {
$name = time() . '-' . $file->getClientOriginalName();
$name = str_replace(' ', '-', $name);
$file->move('task-images', $name);
$task->image()->create(['name' => $name]);
$images = new Image;
$images->name = $name;
}
}
$task->task_name = $request->input('task_name');
$task->task_description = $request->input('task_description');
$task->task_priority = $request->input('task_priority');
$task->task_assigned_by = $request->input('task_assigned_by');
$task->task_assigned_to = $request->input('task_assigned_to');
$task->task_to_be_completed_date = $request->input('task_to_be_completed_date');
$task->task_notes = $request->input('task_notes');
$task->task_status = $request->task_status;
$task->save();
return redirect('/home')->with('success', 'Task Created');
}
public function edit($id)
{
$task = Task::find($id);
return view('tasks.edit', ['task' => $task]);
}
public function update(Request $request, $id)
{
$this->validate($request, [
'task_name' => 'required',
'task_description' => 'required',
]);
$task = Task::find($id);
$task->task_name = $request->input('task_name');
$task->task_description = $request->input('task_description');
$task->task_priority = $request->input('task_priority');
$task->task_assigned_by = $request->input('task_assigned_by');
$task->task_assigned_to = $request->input('task_assigned_to');
$task->task_to_be_completed_date = $request->input('task_to_be_completed_date');
$task->task_notes = $request->input('task_notes');
$task->task_status = $request->input('task_status');
if ($request->hasFile('images')) {
$files = $request->file('images');
foreach ($files as $file) {
$name = time() . '-' . $file->getClientOriginalName();
$name = str_replace(' ', '-', $name);
$file->move('task-images', $name);
$task->image()->create(['name' => $name]);
}
}
$task->update();
return redirect('/home')->with('success', 'Task Updated');
}
public function show($id)
{
$task = Task::find($id);
return view('tasks.show')->with('task', $task);
}
public function destroy($id)
{
$task = Task::findOrFail($id);
// dd($task);
$task->delete();
return redirect('home')->with('success', 'Task Deleted');
}
}
And in the home page where I am calling the delete function, `home.blade.php`, I have:
#extends('layouts.master')
#section('content')
<div class="custom-container">
<div class="row justify-content-center">
<div class="col-md-12">
#include('layouts.includes.messages')
<div class="card w-100">
<div class="card-header text-white" style="background-color: #605ca8;">
<h3 class="card-title">Tasks</h3>
<div class="card-tools">
<a href="tasks/create" class="btn btn-success">
<i class="fas fa-tasks"></i> Add New Task
</a>
</div>
</div>
<!-- /.card-header -->
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Ongoing Tasks</h3>
<div class="card-tools">
<div class="input-group input-group-sm" style="width: 150px;">
<input type="text" name="table_search" class="form-control float-right" placeholder="Search">
<div class="input-group-append">
<button type="submit" class="btn btn-default"><i class="fas fa-search"></i></button>
</div>
</div>
</div>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive p-0">
<table class="table table-hover text-nowrap">
<thead>
<tr>
<th>Task</th>
<th>Priority</th>
<th>Assigned To</th>
<th>Test Environment Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#if($tasks->count() > 0)
#foreach($tasks as $task)
<tr>
<td>{{ $task->task_name }}</td>
<td>{{ $task->task_priority }}</td>
<td>{{ $task->task_assigned_to }}</td>
<td>{{$task->task_to_be_completed_date }}</td>
<td>{{ $task->task_status }}</td>
<td>
<a href="tasks/{{$task->id}}/edit" class="btn btn-primary btn-sm mr-2">
<i class="fa fa-edit"></i> Edit
</a>
<form action="tasks/{{$task->id}}" method="POST" style="display: inline" class="">
#csrf
#method('DELETE')
<button type="submit" class="btn btn-sm btn-danger ml-1 mr-1">
<i class="fa fa-trash"></i> Delete
</button>
</form>
</td>
</tr>
#endforeach
#else
<p class="ml-4 pt-2">No Tasks Found. Please Add one.</p>
#endif
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
</div>
</div>
{{ $tasks->links() }}
</div>
</div>
#endsection
In my filesystem.php under the config folder, I have(just for storage):
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
// 'root' => public_path('task-images'),
],
If I missed anything or codes, please let me know so I can edit my question. Thank you again in advance for helping me with this issue.
You are trying to access a property named images on your instance of Task but there isn't an attribute named images and there isn't a relationship named images, so null is being returned: $task->images == null. You named your relationship image not images, though images would be more correct since this relationship can return many; plural. Change the name of the relationship to images:
public function images()
{
return $this->hasMany(Image::class);
}
Or reference it by its current name: $task->image

How I use relationship in blade template (hasOne) || Laravel

Okay i'm trying get "likes" and "users" in Posts by relationship hasOne.
here is my Post.php Model
class Posts extends Model
{
protected $table = 'posts';
public function User()
{
return $this->hasOne(User::class, 'id', 'user_id');
}
public function Like()
{
return $this->hasOne(Like::class, 'post_id', 'id');
}}
My Blade template
#foreach ($showdeals as $deal)
<div class="tab-pane active" id="home" role="tabpanel">
<div class="card-body">
<div class="profiletimeline">
{{$deal->like->status}}
<br>
{{$deal->user->email}}
<div class="sl-item">
<div class="sl-left"> <img src=" {{asset( '/assets/images/users/2.jpg')}}" alt="user" class="img-circle"> </div>
<div class="sl-right">
<div> {{$deal->user->username}} || {{$deal->subject}} <Br> <span class="sl-date">{{$deal->created_at}}</span>
<div class="m-t-20 row">
<div class="col-md-3 col-xs-12"><img src="{{$deal->image}}" alt="user" class="img-responsive radius"></div>
<div class="col-md-9 col-xs-12">
<p> {{$deal->body}} </p> עבור למוצר </div>
</div>
<div class="like-comm m-t-20"> 2 תגובות <i class="fa fa-heart text-danger"></i> 5 לייקים </div>
</div>
</div>
</div>
</div>
<hr></div>
</div>
#endforeach
And there is my Controller
class PostsController extends Controller
{
public function showdeals()
{
$showdeals = Posts::with( 'User', 'Like')->get();
return view('posts.show', compact('showdeals'));
}
public function helpnewview(){
return view('posts.anew');
}
public function helpnew(Request $request){
//User pick link
$userlink = $request['userlink'];
return \Redirect::route('newdeal', compact('userlink'));
}
public function new(Request $request)
{
//Emdeb user link
$link = Embed::create($request['userlink']);
$linke = $request['userlink'];
return view('posts.new', compact('link', 'userlink', 'linke'));
}
public function create(Request $request)
{
$posts = New Posts;
$posts->user_id = Auth::User()->id;
$posts->subject = $request['subject'];
$posts->body = $request['body'];
$posts->link = $request['link'];
$posts->price = $request['price'];
$posts->image = $request['image'];
$posts->tag = $request['tag'];
$posts->save();
return back();
}
}
Now if I do something like {{$deal->user->email}} its will work,
if I go to something like this {{$deal->like->status}} its does not work,
am I missing something ?
If you want multiple relationships to be eagerly loaded you need to use an array of relationships: Model::with(['rl1', 'rl2'])->get();
public function showdeals()
{
...
$showdeals = Posts::with(['User', 'Like'])->get();
...
}
EDIT:
From that json in the comments that I see, there is no attribute named status in your Like model so thats probably the root of the problem
Controller edit this code
public function showdeals()
{
$showdeals = Posts::all();
return view('posts.show', compact('showdeals'));
}
And blade file code
#foreach ($showdeals as $deal)
<div class="tab-pane active" id="home" role="tabpanel">
<div class="card-body">
<div class="profiletimeline">
{{ $deal->Like->status }}
<br>
{{ $deal->User->email }}
#endforeach
I think everything is good except
{{$deal->like->status}} {{$deal->user->email}}
Please try as
{{$deal->Like()->status}}
<br>
{{$deal->User()->email}}

Categories