Below code in laravel send seller(without Auth) mail not working - laravel

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();
}

Related

Requesting solution for laravel 8 project

I'm an elementary web developer, I'm facing a problem. Please help me solve this. I'm creating both row and column dynamic. for save() is fine. But for update, only name is updated and other item
quantities cannot. Here is my codes.
//for save()
public function stockAdd(Request $request)
{
$validator = validator(request()->all(), ['stock_name' => 'required']);
if($validator->fails()) {
return back()->withErrors($validator);
}
$user_id = Auth::user()->user_id;
$stock_id = random_int(100000, 999999);
$stocks = new Stocks();
$stocks->stock_id = $stock_id;
$stocks->owner_id = $user_id;
$stocks->stock_name = request()->stock_name;
$stocks->my_stock = 0;
$stocks->disable = 0;
$stocks->save();
$brands = Brands::all();
$products = Products::all();
foreach ($brands as $brand){
foreach ($products as $product){
if($product['brand_id'] == $brand['id']){
$product_id = $product->product_id;
$stockitems = new StockItems();
$stockitems->stock_id = $stock_id;
$stockitems->product_id = $product->product_id;
$stockitems->owner_id = $user_id;
if(request()->$product_id > 0){
$stockitems->count = request()->$product_id;
}else{
$stockitems->count = 0;
}
$stockitems->save();
}
}
}
return redirect()->back()->with('successAddMsg','Successfully Added');
}
//for update()
public function stockUpdate(Request $request, $id)
{
$validator = validator(request()->all(), ['stock_name' => 'required']);
if($validator->fails()) {
return back()->withErrors($validator);
}
$stock = Stocks::findOrFail($id);
$stock->stock_name = request()->stock_name;
$stock->my_stock = 0;
$stock->disable = 0;
$stock->update();
$brands = Brands::all();
$products = Products::all();
foreach ($brands as $brand){
foreach ($products as $product){
if($product['brand_id'] == $brand['id']){
$product_id = $product->product_id;
//dd($product_id);
$stockitemitems = DB::table("stock_items")->select("*")->where("owner_id",Auth::user()->user_id)->where("stock_id",$stock->stock_id)->get();
$stockitems->count = $request->input($product_id);
$stockitems->update();
}
}
}
return redirect(route('user.stock-list'))->with('successAddMsg','Successfully Added');
}
The problem shows like this "Creating default object from empty value"

laravel upload image getClientOriginalExtension send email but image not show

Image does't show when i am sending email message
here my code
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use App\Models\Message;
use App\Models\SecondMessage;
use App\Models\ThirdMessage;
class MessageController extends Controller
{
public function message(){
$msg = Message::where('user_id',auth::user()->id)->where('msg_type',1)->first();
return view('admin.create_message',compact('msg'));
}
public function messageStore(Request $request){
$message = Message::where('user_id',Auth::user()->id)->where('msg_type',1)->first();
if(isset($message->id)){
if($request->file){
$file = time().'.'.$request->file->getClientOriginalExtension();
$location = public_path('uploads/' .$file);
$request->file->move($location, $file);
}else{
$location = $message->file;
}
$message->subject = $request->subject;
$message->msg_body = $request->msg_body;
$message->file = $file??'';
$message->save();
}else{
if($request->file){
$file = time().'.'.$request->file->getClientOriginalExtension();
$location = public_path('/' .$file);
$request->file->move($location, $file);
}else{
$location = null;
}
$message = new Message;
$message->subject = $request->subject;
$message->msg_body = $request->msg_body;
$message->user_id = Auth::user()->id;
$message->msg_type = 1;
$message->file = $location;
$message->save();
}
return back()->with('success','First SMTP Message Added Successfully');
}
public function secondMessage(){
$second_msg = SecondMessage::where('user_id',Auth::user()->id)->get();
return view('admin.smtp.second_message',compact('second_msg'));
}
public function secondMessageCreate(){
return view('admin.smtp.second_message_create');
}
public function secondMessageStore(Request $request){
if($request->file){
$file = time().'.'.$request->file->getClientOriginalExtension();
$location = public_path('uploads/' .$file);
$request->file->move($location, $file);
}else{
$file = null;
}
$message = new SecondMessage;
$message->subject = $request->subject;
$message->msg_body = $request->msg_body;
$message->file_status = $request->file_status;
$message->file = $file;
$message->user_id = auth::user()->id;
if($message->save()){
$check = SecondMessage::where('user_id',auth::user()->id)->count();
$message->serial = $check;
}
$message->save();
return back()->with('success','Second SMTP Message Added Successfully');
}
public function secondMessageEdit($id){
$second_msg = SecondMessage::where('id',$id)->where('user_id',Auth::user()->id)->first();
return view('admin.smtp.second_message_edit',compact('second_msg'));
}
public function secondMessageUpdate(Request $request,$id){
$message = SecondMessage::find($id);
if($request->file){
$file = time().'.'.$request->file->getClientOriginalExtension();
$location = public_path('uploads/' .$file);
$request->file->move($location, $file);
}else{
$file = $message->file;
}
$message->subject = $request->subject;
$message->msg_body = $request->msg_body;
$message->file_status = $request->file_status;
$message->file = $file;
$message->save();
return back()->with('success','Second SMTP Message Updated Successfully');
}
public function thirdMessage(){
$third_msg = ThirdMessage::where('user_id',Auth::user()->id)->get();
return view('admin.smtp.third_message',compact('third_msg'));
}
public function thirdMessageCreate(){
return view('admin.smtp.third_message_create');
}
public function thirdMessageStore(Request $request){
if($request->file){
$file = time().'.'.$request->file->getClientOriginalExtension();
$location = public_path('uploads/' .$file);
$request->file->move($location, $file);
}else{
$file = null;
}
$message = new ThirdMessage;
$message->subject = $request->subject;
$message->msg_body = $request->msg_body;
$message->user_id = auth::user()->id;
$message->file = $file;
$message->file_status = $request->file_status;
if($message->save()){
$check = ThirdMessage::where('user_id',auth::user()->id)->count();
$message->serial = $check;
}
$message->save();
return back()->with('success','Third SMTP Message Added Successfully');
}
public function thirdMessageEdit($id){
$third_msg = ThirdMessage::where('id',$id)->where('user_id',auth::user()->id)->first();
return view('admin.smtp.third_message_edit',compact('third_msg'));
}
public function thirdMessageUpdate(Request $request,$id){
$third_msg = ThirdMessage::where('id',$id)->where('user_id',auth::user()->id)->first();
if($request->file){
$file = time().'.'.$request->file->getClientOriginalExtension();
$location = public_path('uploads/' .$file);
$request->file->move($location, $file);
}else{
$file = $third_msg->file;
}
$third_msg->subject = $request->subject;
$third_msg->msg_body = $request->msg_body;
$third_msg->file = $file;
$third_msg->file_status = $request->file_status;
$third_msg->save();
return back()->with('success','Third SMTP Message Updated Successfully');
}
}

Undefined index: password in EloquentUserProvider.php line 126 when JWT auth using mobile number as credential

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

Getting an Error - Creating default object from empty value in Laravel5

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

how to stop giving reward point after 1 commenting

5
i want to if user comment 1st time grant reward +5 after another comment should not get reward
here is my controller logic
public function comment($automobile, Request $request){
$automobile = Automobile::where('slug', $automobile)->firstorfail();
$comment = new Automobilecomment;
$comment->user_id = Auth::user()->id;
$comment->automobile_id = $automobile->id;
$comment->comment = $request->comment;
$comment->save();
$user = User::find(Auth::user()->id);
$reward = 5;
$currentreward = $user->reward;
$user->reward = $currentreward + $reward;
$user->save();
return Redirect::back()->with('status', 'Comment Success');
}
if u need more information let me know because i never did this before like this
Try this:
`
public function comment($automobile, Request $request){
$check = Automobile::where('user_id', Auth::user()->id)->where('automobile_id', $automobile->id)->get()->first();
$automobile = Automobile::where('slug', $automobile)->firstorfail();
$comment = new Automobilecomment;
$comment->user_id = Auth::user()->id;
$comment->automobile_id = $automobile->id;
$comment->comment = $request->comment;
$comment->save();
if(!$check)
{
$user = User::find(Auth::user()->id);
$reward = 5;
$currentreward = $user->reward;
$user->reward = $currentreward + $reward;
$user->save();
}
return Redirect::back()->with('status', 'Comment Success');
}`

Resources