How to display a city?
City.php
public function schools ()
{
return $this->hasMany(SchoolsList::class);
}
SchoolList.php
public function city ()
{
return $this->hasMany(City::class);
}
My Controller.php
public function index ()
{
$inspectors_lists = SubmitApplication::latest()->where->get();
return view('Admin.inspectors-list.all', compact('inspectors_lists'));
}
My Blade
<td>{{ $inspectors_list->school_lists->city->city_name }}</td>
But I get this error.
SQLSTATE[42S22]: Column not found: 1054 Unknown column
cities.schools_list_id in 'where clause' (SQL: select * from
cities where cities.schools_list_id = 1 and
cities .schools_list_id is not null) (View:
C:\xampp\htdocs\project\tvto\resources\views\Admin\inspectors-list\all.blade.php)
Checkout your database. If the column schools_list_id exists in cities table
I think cities.schools_list_id this field not available in your database name please check this.
Related
In laravel tutorial it's said that we can pass an array of conditions in where function. My question is when I pass an array of conditions previously made by me it doesn't work.
Here is the code in documentation:
$users = DB::table('users')->where([
['status', '=', '1'],
['subscribed', '<>', '1'],
])->get();
My code is:
$fields = collect($request->input());
if($fields->has('data')){
$fields = collect($fields->get('data'));
$conditions = collect([]);
if($fields->has('likes')){
$fieldsL = $fields->get('likes');
$conditions->push(['likes', $fieldsL]);
}
if($fields->has('title')){
$fieldsT = $fields->get('title');
$conditions->push(['title', $fieldsT]);
}
$data = DB::table('posts')->select('*')->where($conditions)-
>get();
}
My error message:
Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '[]' in 'where clause' (SQL: select * from `posts` where `[]` is null) in file D:\laravel\lara-api\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 68
PLEASE let me know if it's impossible.
thanks.
I'm trying to make a form to edit data of a specific item in a DB. When I submit I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: update `items` set `0` = Title, `1` = ? where `ID` = 2)
This is how the form redirects:
<form action="{{ url('updateItem/'.$item->ID)}}" method="post" id="updateForm">
Function in controller:
public function updateItem($id, Request $request)
{
$Title = $request->input('Title');
$Kool = $request->input('Koolhydraten');
$Vet = $request->input('Vet');
$Eiwitten = $request->input('Eiwitten');
$Suikers = $request->input('Suikers');
Item::where('ID', $id)
->update(['Title', $Title])
->update(['Koolhydraten', $Kool])
->update(['Vet', $Vet])
->update(['Eiwitten', $Eiwitten])
->update(['Suikers', $Suikers]);
return redirect('/');
}
modify your update query
Item::where('ID', $id)
->update(['Title'=> $Title,'Koolhydraten'=>$Kool,'Vet'=> $Vet,'Eiwitten' => $Eiwitten,'Suikers'=> $Suikers]);
You need to use array with key-value pair as update() parameter. The key needs to be same as column name you want to update and the value is the value to be updated.
When you did ->update(['Title', $Title]) this ['Title', $Title] counts as 2 elements of array which is equivalent to:
[0 => 'Title', 1 => $Title]
the key will be 0 and 1 respectively. Hence why the error shows it can't find column 0.
The correct query should be:
Item::where('ID', $id)->update([
'Title' => $Title,
'Koolhydraten' => $Kool,
'Vet' => $Vet,
'Eiwitten' => $Eiwitten,
'Suikers' => $Suikers
]);
I'm trying to run a update function in my laravel app but every time when i run the function it gives me this error,
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `apps` set `domain` = Testinput.test.com, `apps`.`updated_at` = 2020-03-30 13:18:32 where `id` is null)
Here is my update function in the controller,
public function update(Request $request,App $app, $id)
{
$this->validate($request, [
'domain' => ['required', 'string','min:2', 'max:255'],
],$request->all());
$fullDomain = $request->domain;
$app->domain=$fullDomain;
$app = App::where('appId','=','1')->first()->update($request->all());
return Redirect::back()->with('success',__('sentence.User updated successfully'));
}
I dont't have a column called id in my apps table my column is appId
You gotta inform Laravel that you're using a different primary key from what it's expecting:
In your App model add the $primaryKey property along with the name of the primary key you're using in your database:
class App extends Model
{
protected $primaryKey = 'appId';
}
I have this error when i use :
/**
* #var boolean
*
* #ORM\Column(name="tag", type="boolean")
*/
private $tag;
But i don't understand, in my table i have the field 'tag'.
This error return me a request, and when i run this request in squirrel, all works.
I can not update databae Home vs field is: home_id, title, content:
I Update data in Controller:
$this->Home->home_id =1;
$this->Home->set(array(
'title'=>'sdfjksdf',
'content'=>'lkjskldjfkljsdklj'
));
$this->Home->save();
But it is insert the table home,not is update???
I try
$this->Home->read(null, 1);
But it is error, because Column not found: 1054 Unknown column 'Home.id' in 'where clause'
In the cake php just we use 'ID' for primary keys name.
$this->Home->id =1;
$this->Home->set(array(
'title'=>'sdfjksdf',
'content'=>'lkjskldjfkljsdklj'
));
$this->Home->save();
Try this.
You need to inform CakePHP about your primary key
class Home extends AppModel {
public $primaryKey = 'home_id';
// ...
}