I am getting an error while updating data of logged in user in the database.
Creating default object from empty value
Here are my Controller code:
public function updateProfile(Request $req) {
$name = Session::get('admin-name');
//$user = DB::table('admin')->where('name',$name)->first();
$user = Admin::where('name', $name)->first();
//return dd($user);
//return dd($req->input('admin-name'));
if($req->input('admin-name')!= null) {
$user->name = $req->input('admin-name');
// return dd($user->name);
}
if($req->input('admin-email')!= null) {
$user->email = $req->input('admin-email');
}
if($req->input('admin-address')!= null) {
$user->email = $req->input('admin-address');
}
if($req->input('admin-mobile')!= null) {
$user->mobile = $req->input('admin-mobile');
}
if($req->input('admin-dob')!= null) {
$user->dob = $req->input('admin-dob');
}
$user->save();
return redirect('admin-profile')->with('update-response','Profile Updated successfully');}
When i tried return dd($user); i am getting 'null'.
and when using 'return dd($name);' Screenshot is attached with database.
)]2]2
Related
I want to push the counter in the chat section like below:
public function userChat(Request $request)
{
if (Auth::guard('admin')->check()) {
$user = Auth::guard('admin')->user()->name;
}
if (Auth::guard('web')->check()) {
$user = Auth::user()->name;
$userName = Auth::user()->name;
}
$user_id = $request->get('user_id');
$purpose = $request->get('purpose');
$owner = '';
if ($user == $user_id)
$owner = 'me';
$owner = 'you';
// dd($adminName);
if ($purpose == 'find-user') {
$msg = Chat::where('from', $user)->where('to', $user_id)
->orWhere('from', $user_id)->Where('to', $user)
->get();
// dd($msg);
return response()->json($msg);
} elseif ($purpose == 'admin-user') {
$val = $request->get('val');
$chat = Chat::create([
'message' => $val,
'from' => $user,
'to' => $user_id
]);
$data = 'xxx';
event(new chatNotify($data));
return response()->json(['user' => $user, 'msg' => $val]);
}
}
in my evet channel file:
public $name;
public function __construct($data)
{
$this->name = $data;
}
public function broadcastOn()
{
//return new Channel('chatNotify');
return ['chatNotify'];
}
in my javascript file in the app:
var notificationsWrapper = $('#user-chat');
var notificationsCountElem = notificationsWrapper.find('span[data-count]');
var notificationsCount = parseInt(notificationsCountElem.data('count'));
// Subscribe to the channel we specified in our Laravel Event
var channel = pusher.subscribe('chatNotify');
// Bind a function to a Event (the full Laravel class)
channel.bind('App\\Events\\chatNotify', function () {
notificationsCount += 1;
notificationsCountElem.attr('data-count', notificationsCount);
I have an error connection, no pushing was happen, can somebody help me, please
am using ajax in chat section connection
Below code in laravel send seller(without Auth) mail not working.
public function store(Request $request)
{
$user = null;
if(!Auth::check()){
if(User::where('email', $request->email)->first() != null){
flash(__('Email already exists!'))->error();
return back();
}
if($request->password == $request->password_confirmation){
$user = new User;
$user->name = $request->name;
$user->email = $request->email;
$user->user_type = "seller";
$user->password = Hash::make($request->password);
$user->save();
}
else{
flash(__('Sorry! Password did not match.'))->error();
return back();
}
}
else{
$user = Auth::user();
if($user->customer != null){
$user->customer->delete();
}
$user->user_type = "seller";
$user->save();
}
if(BusinessSetting::where('type', 'email_verification')->first()->value != 1){
$user->email_verified_at = date('Y-m-d H:m:s');
$user->save();
}
$seller = new Seller;
$seller->user_id = $user->id;
$seller->save();
if(Shop::where('user_id', $user->id)->first() == null){
$shop = new Shop;
$shop->user_id = $user->id;
$shop->name = $request->name;
$shop->address = $request->address;
$shop->slug = preg_replace('/\s+/', '-', $request->name).'-'.$shop->id;
if($shop->save()){
flash(__('Your Shop has been created successfully!'))->success();
return redirect()->route('shops.index');
}
else{
$seller->delete();
$user->user_type == 'customer';
$user->save();
}
}
flash(__('Sorry! Something went wrong.'))->error();
return back();
}
Here is my User Login Function,
public function userLogin(Request $request){
$login_type = $request->input('login_type');
if(!$login_type){
return response()->json(['status'=>false,'message'=>'Login type is required']);
}
$input = $request->all();
$login_fb_status = $request->input('fb_login_status');
$array = array();
if($login_fb_status){
$facebook_id = $request->input('facebook_id');
if(!$facebook_id){
return response()->json(['status'=>false,'message'=>'facebook id is required']);
}else{
$user_details = User::where('facebook_id',$facebook_id)->first();
if(count($user_details) <= 0){
return response()->json(['status'=>false,'message'=>'Facebook id does not exist']);
}
$user_id = $user_details->id;
}
$credentials = array('user_id'=>$user_id);
//$credentials = $request->only('facebook_id');
$login_fb_status = 1;
}else{
if($login_type == 'phone_no'){
$credentials = $request->only('phone_no');
}else if($login_type == 'email'){
$credentials = $request->only('email', 'password');
}
$login_fb_status = 0;
}
$token = null;
try {
if (!$token = JWTAuth::attempt($credentials,$array,$login_fb_status)) {
return response()->json(['status'=>false,'message'=>'Invalid Credentials'], 422);
}
} catch (JWTAuthException $e) {
return response()->json(['failed_to_create_token'], 500);
}
$user = JWTAuth::toUser($token);
$account_status=$user->user_status;
return response()->json(['status' => true,'account_status'=>$account_status,'logged_user_details' => $user,'token'=>$token]);
// return response()->json(compact('token'));
}
I am getting Error when try to login with mobile as credential(mobile login not required password in my application ) But When i try with email and password it work perfectly, I am using Laravel 5.4 , The same code work perfectly for mobile login in shared hosting, But Not Working in digital ocean
public function array_from_post($fields) {
$data = array();
foreach ($fields as $field) {
$data[$field] = $this->input->post($field);
$data['category_id'] = $this->input->post('category');
public function save($data, $id = NULL) {
// Set timestamps
if ($this->_timestamps == TRUE) {
$now = date('Y-m-d H:i:s');
$id || $data['created'] = $now;
$data['modified'] = $now;
}
// Insert
if ($id === NULL) {
!isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
$this->db->set($data);
$this->db->insert($this->_table_name);
$id = $this->db->insert_id();
}
// Update
else {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->set($data);
$this->db->where($this->_primary_key, $id);
$this->db->update($this->_table_name);
}
return $id;
}
On save this code returns column picture cannot be null. When i do the direct method without using the method array_from_post(), data is saved in the database but i can not save a post to be published at a future date.
I have just created a library class in laravel.
class Message {
public static $data = array();
public function __construct() {
// If session has flash data then set it to the data property
if (Session::has('_messages')) {
self::$data = Session::flash('_messages');
}
}
public static function set($type, $message, $flash = false) {
$data = array();
// Set the message properties to array
$data['type'] = $type;
$data['message'] = $message;
// If the message is a flash message
if ($flash == true) {
Session::flash('_messages', $data);
} else {
self::$data = $data;
}
}
public static function get() {
// If the data property is set
if (count(self::$data)) {
$data = self::$data;
// Get the correct view for the message type
if ($data['type'] == 'success') {
$view = 'success';
} elseif ($data['type'] == 'info') {
$view = 'info';
} elseif ($data['type'] == 'warning') {
$view = 'warning';
} elseif ($data['type'] == 'danger') {
$view = 'danger';
} else {
// Default view
$view = 'info';
}
// Return the view
$content['body'] = $data['message'];
return View::make("alerts.{$view}", $content);
}
}
}
I can use this class in my views calling Message::get(). In the controllers, I can set the message as Message::set('info', 'success message here.'); and it works perfectly fine.
However, I can not use this class for flash messages redirects using Message::set('info', 'success message here.', true). Any idea, whats wrong in this code?
First problem is the constructor function is not called when using the above get and set methods, with minor modification the code is now working. :)
class Message {
public static $data = array();
public static function set($type, $message, $flash = false) {
$data = array();
// Set the message properties to array
$data['type'] = $type;
$data['message'] = $message;
// If the message is a flash message
if ($flash == true) {
Session::flash('_messages', $data);
} else {
self::$data = $data;
}
}
public static function get() {
// Check the session if message is available in session
if (Session::has('_messages')) {
self::$data = Session::get('_messages');
}
// If the data property is set
if (count(self::$data)) {
$data = self::$data;
// Get the correct view for the message type
if ($data['type'] == 'success') {
$view = 'success';
} elseif ($data['type'] == 'info') {
$view = 'info';
} elseif ($data['type'] == 'warning') {
$view = 'warning';
} elseif ($data['type'] == 'danger') {
$view = 'danger';
} else {
// Default view
$view = 'info';
}
// Return the view
$content['body'] = $data['message'];
return View::make("alerts.{$view}", $content);
}
}
}