Just created new laravel (5.4) project , uploaded into shared hosting
showing following error
(1/1) FatalErrorException
syntax error, unexpected 'App' (T_STRING)
in HomeController.php (line 1)
what is the reason behind this , why it is showing error in word App , i thinks its default namespace name right? , working fine in local (WIN 10 , XAMPP )
Please help!
Code of HomeController.php is very huge...still posting first few lines
namespace App\Http\Controllers;
use App\Coupon;
use App\Footer;
use App\Home;
use App\Http\Models;
use App\Merchant;
use App\Register;
use App\Settings;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
use MyPayPal;
use Session;
class HomeController extends Controller
{
/*
|--------------------------------------------------------------------------
| Default Home Controller
|--------------------------------------------------------------------------
|
| You may wish to use controllers instead of, or in addition to, Closure
| based routes. That's great! Here is an example controller method to
| get you started. To route to this controller, just add the route:
|
| Route::get('/', 'HomeController#showWelcome');
|
*/
public function siteadmin()
{
return Redirect::to('siteadmin');
}
public function index()
{
$city_details = Register::getCityDetails();
$header_category = Home::getHeaderCategory();
$product_details = Home::getProductDetails();
$women_product = Home::getWomenProduct();
$most_visited_product = Home::getMostVisitedProduct();
$deals_details = Home::getDealsDetails();
$auction_details = Home::getAuctionDetails();
$get_product_details_by_cat = Home::getProductDetailsByCategory($header_category);
$category_count = Home::getCategoryCount($header_category);
$get_product_details_typeahed = Home::getProductDetailsTypeahed();
$main_category = Home::getHeaderCategory();
$sub_main_category = Home::getSubMainCategory($main_category);
$second_main_category = Home::getSecondMainCategory($main_category, $sub_main_category);
$second_sub_main_category = Home::getSecondSubMainCategory();
$get_social_media_url = Home::getSocialMediaUrl();
$cms_page_title = Home::getCmsPageTitle();
$country_details = Register::getCountryDetails();
$addetails = Home::getAdDetails();
$noimagedetails = Home::getNoimageDetails();
$getbannerimagedetails = Home::getbannerimagedetails();
$getmetadetails = Home::getmetadetails();
$getlogodetails = Home::getlogodetails();
$get_contact_det = Footer::getContactDetails();
$getanl = Settings::social_media_settings();
$general = Home::getGeneralSettings();
if (Session::has('customerid')) {
$navbar = view('includes.loginnavbar')->with('country_details', $country_details)->with('metadetails', $getmetadetails)->with('general', $general);
} else {
$navbar = view('includes.navbar')->with('country_details', $country_details)->with('metadetails', $getmetadetails)->with('general', $general);
}
$header = view('includes.header')->with('header_category', $header_category)->with('logodetails', $getlogodetails);
$footer = view('includes.footer')->with('cms_page_title', $cms_page_title)->with('get_social_media_url', $get_social_media_url)->with('get_contact_det', $get_contact_det)->with('getanl', $getanl);
return view('index')->with('navbar', $navbar)->with('header', $header)->with('footer', $footer)->with('header_category', $header_category)->with('product_details', $product_details)->with('deals_details', $deals_details)->with('auction_details', $auction_details)->with('get_product_details_by_cat', $get_product_details_by_cat)->with('most_visited_product', $most_visited_product)->with('category_count', $category_count)->with('get_product_details_typeahed', $get_product_details_typeahed)->with('main_category', $main_category)->with('sub_main_category', $sub_main_category)->with('second_main_category', $second_main_category)->with('second_sub_main_category', $second_sub_main_category)->with('addetails', $addetails)->with('noimagedetails', $noimagedetails)->with('bannerimagedetails', $getbannerimagedetails)->with('metadetails', $getmetadetails)->with('women_product', $women_product)->with('get_contact_det', $get_contact_det)->with('general', $general);
}
Related
on my modal, I have two functions which I have used to log the data when it has been changed. those are below.
namespace App\Models;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Contracts\Activity;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Receivinglogentry extends Model
{
use HasFactory;
use LogsActivity;
protected $fillable = [
'status',
'amt_shipment',
'container',
'po',
'etd_date',
'eta_date',
];
protected $casts = [
'po_ref' => 'json',
];
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()->logOnly(['*'])->logOnlyDirty();
}
public function tapActivity(Activity $activity,string $eventName)
{
$current_user = Auth::user()->name;
$event = $activity->attributes['event'];
$data = $activity->relations['subject']->attributes['container'];
$masterID = $activity->relations['subject']->attributes['id'];
$activity->description = "{$current_user} has {$event} Container : {$data}";
$activity->causer_name = $current_user;
$activity->master_id = $masterID ;
$activity->log_name = 'Receivinglogentry';
}
}
fillable data status has been stored as an integer value. but I have to log it as a string value something like PENDING or ACTIVE. any recommendation to log attributes customizably is appricated.
You can try ENUM concept but in Laravel 9 onwards. Here is a reference link - https://enversanli.medium.com/how-to-use-enums-with-laravel-9-d18f1ee35b56
There they describe about an enum UserRoleEnum:string which you can format as your own requirement.
In your case, the key itself is a number. So I suggest to make it as string as below.
enum StatusEnum:string
{
case STATUS_101 = 'Pending';
case STATUS_34 = 'Completed';
case STATUS_22 = 'On hold';
}
And then call it with your fillable status something like "STATUS_" + $fillable.status
If not using Laravel 9, you may try as below described in :
https://stackoverflow.com/a/55298089/2086966
class MyClass {
const DEFAULT = 'default';
const SOCIAL = 'social';
const WHATEVER = 'whatever';
public static $types = [self::DEFAULT, self::SOCIAL, self::WHATEVER];
and then write the rule as:
'type' => Rule::in(MyClass::$types)
I will use unique number using nanoid package from nodejs to laravels,
but i get error this.
this is mycontroller.
<?php
namespace App\Http\Controllers;
use DateTime;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class BooksController extends Controller
{
public function addBooks(Request $request)
{
$data =([
'id' = nanoid(16);
'name'= $request->input('bookName');
'year'= $request->input('tahunT');
'author'= $request->input('author');
'summary'= $request->input('publishers');
'publisher'= $request->input('pageCount');
'pageCount' = $request->input('ReadPage');
'readPage'= $request->input('');
'finished' = $pageCount == $readPage ? true : false;
'reading' = $readPage > 0 ? true : false;
'insertedAt'= new DateTime();
'updatedAt'= $insertedAt;
}
}
this is my app.js
require('./bootstrap');
const { nanoid } = require('nanoid');
when I use the nanoid, error like this
syntax error, unexpected '=' , expecting ']'.
What I should to do? or you can give the other opinion to generate unique number?
You cannot use it in plain PHP, you are confusing NPM (JavaScript) with Laravel (PHP).
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\News;
use App\User;
use App\Event;
public function index()
{
$datanews['newss'] = News::orderBy('created_at','desc')->get();
$dataevent['events'] = Event::orderBy('created_at','desc')->get();
$user['users'] = User::all();
return view('user/aktuelles.index',$datanews, $dataevent,$user);
}
this is a part of my controller, i can show news and events in my view but everytime it says it can not find the variable user?
i dont know why because i dont know why it shows me the other variables but not the user variable???
in my view i can see the other variables like this:
#foreach ($newss as $news)
{{$news->newstitel}}
#endforeach
but i want to show user like this:
{{$user[1]->avatar}}
i tried everything so i tried so look my controller like this:
$user = DB::table('users')->get();
or get the variable via compact
and i tried exactly the same so like this
$user['users'] = User::orderBy('created_at','desc')->get();
and a foreach in my view but it can not found the variable user??
i dont know why
this is the error
Undefined variable: users
return view('user.aktuelles.index', compact('datanews', 'dataevent', 'user');
I am not sure how the helper view() handles the 4th parameter you are passing. According to the docs you can pass data like this:
return view('user/aktuelles.index',[
'datanews' => $datanews,
'dataevent' => $dataevent,
'user' => $user,
]);
or
return view('user/aktuelles.index')->with([
'datanews' => $datanews,
'dataevent' => $dataevent,
'user' => $user,
]);
Maybe give this way a try.
Edit:
The view() helper accepts 3 Parameters: $view = null, $data = [], $mergeData = [] so the 4th parameter you are trying to pass is not even working. You have to pass your data as second parameter or with the chained function with(array $data).
You have to return value in view like below method:
Change this line
$user['users'] = User::orderBy('created_at','desc')->get();
To
$user = User::orderBy('created_at','desc')->get();
return view('user/aktuelles.index', ['datanews' => $datanews,'dataevent'=> $dataevent,'users'=>$user]);
Now, You will get result inside your view using 'users'.
You are not passing variables to view correctly use with or compact to pass variables to view.
i prefer compact as it is simple and easier.
Passing data to view using compact:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\News;
use App\User;
use App\Event;
public function index()
{
$datanews = News::orderBy('created_at','desc')->get();
$dataevent = Event::orderBy('created_at','desc')->get();
$user = User::all();
return view('user.aktuelles.index',compact('datanews', 'dataevent','user'));
}
Passing variables to view using with:
public function index()
{
$datanews = News::orderBy('created_at','desc')->get();
$dataevent = Event::orderBy('created_at','desc')->get();
$user = User::all();
return view('user.aktuelles.index)->with(['datanews' => $datanews,'dataevent'=> $dataevent,'users'=>$user]);
}
You should try this:
use Illuminate\Support\Facades\DB;
use App\News;
use App\User;
use App\Event;
public function index()
{
$data['news'] = News::orderBy('created_at','desc')->get();
$data['events'] = Event::orderBy('created_at','desc')->get();
$data['users'] = User::all();
return view('user/aktuelles.index', $data);
}
I have this route:
Route::get('/test',['as'=>'test','custom_key'=>'custom_value','uses'=>'TestController#index'])
I've been tried to use $routeProfile=route('test');
But the result is returned url string http://domain.app/test
I need ['as'=>'test','custom_key'=>'custom_value'] so that I can get the $routeProfile['custom_key']
How can I get 'custom_value' based on route name ?
For fastest way, now I use this for my question:
function routeProfile($routeName)
{
$routes = Route::getRoutes();
foreach ($routes as $route) {
$action = $route->getAction();
if (!empty($action['as']) && $routeName == $action['as']) {
$action['methods'] = $route->methods();
$action['parameters'] = $route->parameters();
$action['parametersNames'] = $route->parametersNames();
return $action;
}
}
}
If there's any better answer, I will be appreciate it.
Thanks...
Try this:
use Illuminate\Support\Facades\Route;
$customKey = Route::current()->getAction()['custom_key'];
I believe you are looking for a way to pass variable to your route
Route::get('/test/{custom_key}',[
'uses'=>'TestController#index',
'as'=>'test'
]);
You could generate a valid URL like so using
route('test',['custom_key'=>'custom_key_vale'])
In your view:
<a href="{route('test',['custom_key'=>'custom_key_vale'])}"
In your controller method:
....
public function test(Request $request)
{
$custom_key = $request->custom_key;
}
....
You can try one of the below code:
1. Add use Illuminate\Http\Request; after namespace line code
public function welcome(Request $request)
{
$request->route()->getAction()['custom_key'];
}
2. OR with a facade
Add use Route; after namespace line code
and use below into your method
public function welcome()
{
Route::getCurrentRoute()->getAction()['custom_key'];
}
Both are tested and working fine!
I work with laravael 5.3.9 .
In my controller I use
Illuminate\Support\Facades\Input;
But when I try to get input from a user form using method post like that :
function add(){
$fullName = Input::post('fullName' , 'test');
I get this error .
the only method that Input class has is "get" .
I dont want that in my system I want to work with method post , delete , put ....
I guess, Input::post method is not used with L5.3. Use the Request facade OR $request to get your input variable.
Try this in your controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class area_owners extends Controller
{
function add(Request $request)
{
// I assume all these input variable have same name in you FORM.
$fullName = $request->input('fullName');
$smsCode = $request->input('smsCode');
$authorizationId = $request->input('authorizationId');
$areaNumber = $request->input('areaNumber');
$neigh_project_Id = $request->input('neigh_project_Id');
$area_owners = DB::table('area_owners')
->insert(['fullName'=>$fullName,
'smsCode'=>$smsCode,
'authorizationId'=>$authorizationId,
'areaNumer'=>$areaNumber,
'neigh_project_Id'=>$neigh_project_Id]);
return view('area_owners_add', ['area_owners' => $area_owners]);
}
}
Let me know if it helps.