简体   繁体   中英

Use of undefined constant in Laravel

I am having an issue with siteSocialSettingsData in my blade view I am getting

Use of undefined constant facebook - assumed 'facebook'

However I am confused as to why its happening as the GeneralSettings area/section is working how it should and they are both the same sections of code

In my function I have done var_dump($siteSocialSettingsData->facebook); and it works as I want it

Function:

$siteSettingsDB          = GeneralSettings::get();
$siteSettingsData        = $siteSettingsDB[0];

$siteSocialSettingsDB    = SocialSettings::get();
$siteSocialSettingsData  = $siteSocialSettingsDB[0]; 

return view('admin.pages.settings.general.general', compact('pageTitle','siteName', 'pageName', 'fullName','cpuUsage','memoryUsage', 'siteSettingsData', 'siteSocialSettingsData'));

Blade:

<input class="form-control updateField" data-id="facebook" data-url="{{ route('socialDataSubmit', facebook )}}" data-title="Facebook" name="facebook" placeholder="Facebook" type="input"  value="{{ old('facebook', $siteSocialSettingsData->facebook)}}"> <span class="input-group-btn"><button class="btn btn-default edit" type="button"><span class="glyphicon glyphicon glyphicon-pencil"></span></button></span>

You are just entering facebook without telling PHP if that's a variable or a string and that's why you're getting the error. The error is in your blade view, at the data-url attribute, when you're calling the route function (check the second parameter).

You need to change your view to:

<input class="form-control updateField" data-id="facebook"
    data-url="{{ route('socialDataSubmit', $siteSocialSettingsData->facebook )}}"
    data-title="Facebook" name="facebook" placeholder="Facebook" type="input"
    value="{{ old('facebook', $siteSocialSettingsData->facebook)}}">

<span class="input-group-btn">
    <button class="btn btn-default edit" type="button">
        <span class="glyphicon glyphicon glyphicon-pencil"></span>
    </button>
</span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM