Class 'App/Board' not found . Why happen this error - laravel

I using relation of model on laravel.
when I access to viewpage but show error [Class 'App/Board' not found].
I have Board.php in App folder absolutely.
I have no idea what's wrong.
I spent 1hours .
please give me advice.
controller
namespace App\Http\Controllers;
use App\Board;
use App\Person;
use App\Http\Requests\PostRequest;
use Illuminate\Http\Request;
class ReviewController extends Controller
{
.
.
.
public function show()
{
$items_p = Person::all();
$data = [
'items_p' => $items_p
];
return view('Review.show', $data);
}
}
Board.php(In App folder)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Board extends Model
{
protected $fillable = [
'person_id',
'message'
];
public function getData()
{
return $this->message;
}
}
Person.php(In App folder)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
protected $fillable = [
'name'
];
public function board()
{
return $this->hasOne('App/Board');
}
}
View(Review.show)
.
.
.
<ul>
<li>
#foreach ($items_p as $item)
{{$item->name}}
{{$item->board->getData()}}
#endforeach
</li>
</ul>
・
・
・

You have an error in slash. you have passed /. it should be \.
class Person extends Model
{
protected $fillable = [
'name'
];
public function board()
{
return $this->hasOne('App\Board');
}
}

Related

Data can not be appears, database relation one to one Laravel

ErrorException
Trying to get property 'category_name' of non-object (View: D:\xampp\htdocs\e-catalog\resources\views\backend\pages\gmproducts.blade.php)
This is my blade code below.
<tbody>
#foreach($gmproducts as $no => $gm)
<tr>
<td>{{$no+1}}</td>
<td>{{$gm->type}}</td>
<td>{{$gm->gmcategories->category_name}}</td>
<td>{{$gm->gram}}</td>
<td>{{$gm->carat}}</td>
<td>#currency($gm->price)</td>
<td><a class="test-popup-link" href="{{url('p_goldmart/'.$gm->file)}}">Preview</a></td>
<td>
<i class="fa fa-edit"></i>
<i class="fa fa-trash-o"></i>
</td>
</tr>
#endforeach
</tbody>
This is my model Gmcategories & Gmproducts.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Gmcategories extends Model
{
protected $table = "gmcategories";
protected $fillable = ['category_name'];
public function gmproducts()
{
return $this->hasOne('App\Gmproducts');
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Gmproducts extends Model
{
use SoftDeletes;
protected $table = "gmproducts";
protected $fillable = ['type', 'category_id', 'gram', 'carat', 'price', 'file'];
protected $dates = ['deleted_at'];
public function gmcategories()
{
return $this->belongsTo('App\Gmcategories');
}
}
This is my controller.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Gmproducts;
use App\Gmcategories;
use File;
class GmproductsController extends Controller
{
public function index()
{
$gmproducts = Gmproducts::orderBy('id', 'desc')->get();
$trash = Gmproducts::orderBy('deleted_at', 'desc')->onlyTrashed()->count();
return view('backend.pages.gmproducts', compact('gmproducts', 'trash'));
}
public function create()
{
$gmcategories = Gmcategories::all();
return view('backend.pages.create', compact('gmcategories'));
}
Just info, I just rename my model and controller. Does it have any effect? Thanks.
// Gmcategories model
public function gmproducts()
{
return $this->hasOne('App\Gmproducts', 'category_id');
}
// Gmproducts model
public function gmcategories()
{
return $this->belongsTo('App\Gmcategories', 'category_id');
}
Your BuildImage model should be
Get the source type of the Building Image.
public function type() {
return $this->hasOne('App\BuildingType',"id","source");
}
And BuildingType Model should be
Get the Building Image that owns the building type.
public function buildingImage()
{
return $this->belongsTo('App\BuildingImage',"source","id");
}

How to pass variable from Controller to Nova Recource?

I want to pass $defaultFrom from NewsletterController.php:
<?php
namespace App\Http\Controllers;
use App\Mail\NewsletterMail;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
class NewsletterController extends Controller
{
public function send()
{
$defaultFrom = 'newsletter#stuttard.de';
DB::table('newsletter_mails')->insert(['from' => $defaultFrom]);
$emails = DB::select('select * from newsletters order by id desc');
foreach ($emails as $email) {
Mail::to($email)->send(new NewsletterMail());
}
}
}
to NewsletterMail.php:
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
class NewsletterMail extends Resource
{
public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
Text::make('From', 'from')->default($defaultFrom)->placeholder($defaultFrom),
];
}
}
I've tried to put public $defaultFrom; above the fields() function or call new NewsletterMail($defaultFrom) but this seems to be wrong syntax. Sorry, I'm a bit new to Laravel.
I assume that you have Newsletter model. Move $defaultFrom to model as public const DEFAULT_FROM = 'newsletter#stuttard.de';. After doing this, you can call it's value in both places using Newsletter::DEFAULT_FROM.

Trying to get property 'name' of non-object (View: C:\xampp\htdocs\laravel\resources\views\Faculties\show.blade.php)

this is my model Faculty
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Faculty extends Model { protected $fillable = [ 'name', 'id', 'date_of_birth', 'age', 'qualification', 'religion', 'gender', 'phone_number', 'address', 'blood_group', 'email' ]; }
this is my FacultiesController
namespace App\Http\Controllers;
use App\Faculty;
use Illuminate\Http\Request;
class FacultiesController extends Controller
{
public function show(Faculty $faculty)
{
$faculties = Faculty::where('id',$faculty->id)->first();
return view('Faculties.show',['Faculty'=>$faculties]);
}
}
this is my route web.php
Route::resource('Faculties','FacultiesController');
this is my blade file show.blade.php
<ul>
<li class="list-group-item">{{ $Faculty->name }}</a></li>
</ul>
There are a couple problems here.
First, this is unnecessary:
public function show(Faculty $faculty)
{
$faculties = Faculty::where('id',$faculty->id)->first();
The routing logic already passes the Faculty model to your function, so you're looking it up twice (and you can also simplify such logic by using Faculty::find() instead of where()->first()).
This should work fine:
public function show(Faculty $faculty)
{
return view('Faculties.show',['Faculty'=>$faculty]);
}
If it doesn't, it may be that there's no Faculty model in your database matching that ID.

LARAVEL 5.6 - error Trying to get property 'nsc' of non-object

I want to echo value of NSC from table Group Class but i get this error Trying to get property 'nsc' of non-object
Table Item Name
Table Group Class
Model Item Name
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class ItemName extends Model
{
protected $table = 'tbl_item_name';
protected $fillable = [
'inc',
'item_name',
'short_name',
'definition_eng',
'definition_ind'
];
public function GroupClass()
{
return $this->belongsTo('App\GroupClass', 'nsc', 'inc');
}
}
Model Group Class
namespace App;
use Illuminate\Database\Eloquent\Model;
class GroupClass extends Model
{
protected $table = 'tbl_group_class';
protected $fillable = [
'inc',
'nsc',
'description',
'main_group'
];
public function ItemName()
{
return $this->belongsTo('App\ItemName', 'inc', 'nsc');
}
}
Blade
<td>{{ $ItemName->GroupClass->nsc }}</td>
Please help to solve this problem, thank you so much
You should try this::
Blade
<td> {{ isset($ItemName->GroupClass) ? $ItemName->GroupClass->nsc : '' }} </td>
Model Item Name
public function GroupClass()
{
return $this->belongsTo('App\GroupClass', 'inc', 'nsc');
}
Model Group Class
public function ItemName()
{
return $this->belongsTo('App\ItemName', 'nsc', 'inc');
}

How to load and display data from revisions table form VentureCraft/revisionable in Laravel 5.4?

My Route
Route::get('news-logs', 'Backend\ChangeLog\ChangeLogController#changeLogNews')->name('change-log-news');
My Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class News extends Model
{
protected $table = 'news';
use \Venturecraft\Revisionable\RevisionableTrait;
protected $revisionCreationsEnabled = true;
protected $revisionEnabled = true;
public static function boot()
{
parent::boot();
}
public function revisionHistory(){
$news = News::all();
$history = $news->revisionHistory;
}
public function getRouteKeyName()
{
return 'slug';
}
public function months($year) {
$queryResult = DB::table('news')->select(DB::raw('MONTH(order_date) as month'), DB::raw('YEAR(order_date) as year'))->where(DB::raw('YEAR(order_date)'), $year)->orderBy(DB::raw('MONTH(order_date)'))->get();
$months = collect($queryResult)->unique('month');
return $months;
}
}
My Controller
<?php
namespace App\Http\Controllers\Backend\ChangeLog;
use App\Models\News;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ChangeLogController extends Controller
{
public function changeLogNews(){
$news = News::all();
$history = $news->revisionHistory;
dd($history);
return view('backend.change-log.history',compact('history'));
}
}
My View
#foreach($history->revisionHistory as $log )
<li>
{{ $log->userResponsible()->name }} changed {{ $log->fieldName() }} from {{ $log->oldValue() }} to {{ $log->newValue() }}</li>
#endforeach
Now When ever I load the page, it says - "Property [revisionHistory] does not exist on this collection instance". I would like to get any help form your side.
Thank You
The $history doesn't have a revisionHistory property. The $history is the result of $news->revisionHistory.

Resources