Ok so I'm getting Trying to get property of non-object
when I try and get the data from the DB using $settings = AdminSettings::first();
here is the controller code
<?php
namespace App\Http\Controllers\AdminSettings;
use App\AdminSettings\AdminSettings;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class AdminSettingsController extends Controller
{
public function index()
{
$settings = AdminSettings::first();
return view('admins.settings.settings', compact('settings'));
}
}
here is the modal code
<?php
namespace App\AdminSettings;
use Illuminate\Database\Eloquent\Model;
class AdminSettings extends Model
{
protected $table = 'site_settings';
protected $fillable = [
'site_title', 'site_url', 'email_from', 'email_to', 'timezone', 'date_format', 'time_format',
];
}
here I'm trying to put the site_title into the input but I get Trying to get property of non-object
<div class="form-group">
<label for="site_title" class="form-label">Site Title</label>
<input type="text" class="form-control" name="site_title" id="site_title" value="{{ $settings->site_title }}"/>
</div>
when I try to dd($settings);
i get null
You've said the table is empty, so make settings object optional
:
{{ optional($settings)->site_title }}
You can use or
operator too:
{{ $settings->site_title or '' }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With