mardi 30 avril 2019

INSERT new row or DELETE old row IF it already exists using laravel

I am assigning multiple skills to an employee using checkboxes. when a user checks the checkbox a new record is inserted into pivot table. if a user unchecks the checkbox a record is deleted.

Now i am wondering if there is any function for insert or delete like there exists for new insert or update which is updateOrCreate to update an existing record or create a new record if none exists.

I can do it the hard way. but just want to know if there is any function for this like updateOrCreate.



via Chebli Mohamed

vendredi 26 avril 2019

jeudi 25 avril 2019

Why all token is valid using jwt auth in laravel

When I login multiple time and then JWT Auth generate multiple token and all token is valid why. I need only one token valid.



via Chebli Mohamed

samedi 20 avril 2019

Cannot use object of type stdClass as array (View:

I want to use data 2 query in 1 view but Error Cannot use object of type stdClass as array (View: public function adtranspc(Request $request) { $writter = Writter::all(); $processmaster = DB::table('rocessmaster') ->where('pcm_bname', 'LIKE', "%Social%") ->get(); return view('processspj.adtranspc',[ 'writter' => $writter, 'processmaster' => $processmaster ]};

  *This is my view (this error here)
   <table id="table2" class="table table-hover table-striped">
      <tr>
         <th scope="col"></th>
         <th scope="col">Colname1</th>
      </tr>
       @foreach ($processmaster as $item)
        <tr>
          <td></td>
          <td></td>
        </tr>
       @endforeach
  </table>



via Chebli Mohamed

samedi 13 avril 2019

Effiecient way to get data from database in foreach

I am loading data from excel. In foreach I am checking for each record if it does exist in database:

$recordExists = $this->checkIfExists($record);

function checkIfExists($record) {
    $foundRecord = $this->repository->newQuery()
        ->where(..., $record[...])
        ->where(..., $record[...])
        ...
        ->get();
}

When the excel contains up to 1000 values which is relatively small piece of data - the code runs around 2 minutes. I am guessing this is very inefficient way to do it.

I was thinking of passing the array of loaded data to the method checkIfExists but then I could not query on the data.

What would be a way to proceed?



via Chebli Mohamed

vendredi 12 avril 2019

Laravel cannot get more than 15k records

I have a very simple query to get records from the database: \DB::table("table")->get();

When I try to get more than ±145000 records from the database I am getting: 500 server error.

The code like: \DB::table("table")->take(14500)->get(); although works. When I try to get more than 15k I get the error immediately without any loading or further information. I cannot get any more info from logs as well. An odd thing is that when I write that code to tinker - I can get all records. (with eloquent works the same)



via Chebli Mohamed

Modify from in laravel 5.1

What if I want to use different email addresses depending on the relatedness of the form.

For example, I want to use donotreply@domain.com for my contact form. Then I want to use myemail@domain.com for my registration form. How can I implement this?

I've already tried to use the from method but didn't work. Please see my code below.

Mail::later(10,
    [],
    compact('inputs'),
    function($m) use ($email, $inputs){
        $m->from('myemail@domain.com', 'Name');
        $m->to($email)->subject($inputs['subject']);
    }
);



via Chebli Mohamed

jeudi 11 avril 2019

Laravel How I can return view data with respone json (both in 1 time)?

public function index(Request $request)
{
    $search_book = $request->id;

    $proc=DB::select(DB::raw("SELECT * FROM BOOKS WHERE BOOKID = '$Search_book'")

    if ($search_book!="") {
        return response()->json($proc);
        return view('status.status',[ 
          'proc' => $proc
    ]);
}

How to return 2 data



via Chebli Mohamed

mercredi 10 avril 2019

I have store the image file in admin through post method but when trying to put the same code for pdf/word its not working

I want to upload pdf file on page but its not working as done with image and its working

I have made a column filepath for pdf/word then code in postcontroller but not working

public function store(Request $request) {

    $this->validate($request, [


       'title' =>'required',
        'featured'=>'required|image',
        'content'=>'required',
        'category_id'=>'required'

    ]);

    $featured= $request->featured;
    $featured_new_name=time().$featured->getClientOriginalName();
    $featured->move('uploads/posts', $featured_new_name);

    $post = Post::create([

        'title'=>$request->title,
        'content'=>$request->content,
        'featured'=>'uploads/posts/'. $featured_new_name,
        'category_id'=>$request->category_id,
        'slug'=>str_slug($request->title)

and when I trying to add "filepath column name in data base" for pdf/ word then using in public function store(Request $request) {

    $this->validate($request, [


       'title' =>'required',
        'featured'=>'required|image',
        'content'=>'required',
        'category_id'=>'required',

        'file' => 'required',

    ]);

    $featured= $request->featured;
    $featured_new_name=time().$featured->getClientOriginalName();
    $featured->move('uploads/posts', $featured_new_name);

    $file=$request->file;
    $file=time().$file->getClientOriginalName();
    $extension = Input::file('file')->getClientOriginalExtension();

    $filename = rand(11111111, 99999999). '.' . $extension;
    $fullPath = $filename;
    $request->file('file')->move(base_path() . '/uploads/pdf/', $filename);



    $post = Post::create([

        'title'=>$request->title,
        'content'=>$request->content,
        'featured'=>'uploads/posts/'. $featured_new_name,
        'file'=>'uploads/pdf' .$filename,

        'category_id'=>$request->category_id,
        'slug'=>str_slug($request->title)


    ]);


  Session::flash('success', 'New Blog has been Published on Website for Particular Menu');

  return redirect()->back();

}



via Chebli Mohamed

lundi 1 avril 2019

Class App\Http\Controllers\Api\DeliveryController does not exist

Other functions in the controller are working fine but the error shows up when I try to call this function.

I have checked through all the related posts but couldn't solve my problem.

Class App\Http\Controllers\StudentController does not exist in Laravel 5

https://laracasts.com/discuss/channels/laravel/class-apphttpcontrollersusercontroller-does-not-exist?page=1

The controller

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\CommonController;
use DateTime;
use Dompdf\Dompdf;
use Validator;
class DeliveryController extends Controller{

    public function __construct()
    {
        $this->middleware('auth');
    }
        //codes

       //The function in the controller
        public function fetchItemList($formId)
        {
        //codes
        return response()->json(['Item' => $item]);
        }

routes.php

Route::get('fetchItemList/{id}', 'Api\DeliveryController@fetchItemList');



via Chebli Mohamed