sghimire

sghimire

Member Since 1 Year Ago

Experience Points
13,890
Total
Experience

1,110 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
134
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 3
13,890 XP
Sep
27
1 year ago
Activity icon

Replied to Run Artisan Command

Yes I am thinking to use ajax to check the file to let user know that the file is ready for them to download, however, is there anyway send the job in the background till the process finished?

many thanks!

Sep
26
1 year ago
Activity icon

Replied to Run Artisan Command

When background process will be completed then User will be able to see the downloadable button, then hits the file buttons, and download the required file from the storage. That's way I am planning to deliver it to user. I will be happy to get any suggestion on this.

Cheers,

Activity icon

Replied to Run Artisan Command

Thanks Snapey! I am trying to let the user to download their paginated search results in the file(in one go) so they can generate the file straight a way rather than running in the cron scheduler.

please can you give one example for your response as below

You do need to be using the queue properly though and not as sync, and with a queue worker.

Thanking in advanced!

Sep
25
1 year ago
Activity icon

Started a new conversation Run Artisan Command

I have been trying to write a large file and calling artisan command from controller, command runs but I am getting time out all the time. Is there anyway to run this artisan command in queue from api(browser) then send it to run in the background like in the terminal, please?

---controller

Artisan::queue('test:ExecuteFile', ['filter' => $request->all(),'--queue' => $fileName]);

---app/Console/kernel.php

 public function queue($command, array $parameters = [], $queue = 'default')
    {
        $this->app['Illuminate\Contracts\Queue\Queue']->push(
            'Illuminate\Foundation\Console\QueuedJob', [$command, $parameters], $queue
        );
    }

---
public function handle()
{
        //getting the filter 
        $filter = $this->argument('filter');

        //getting optional values
        $queueName = $this->option('queue');

    $this->pathToFiles = storage_path() . '/temp/';

    //open the file and add first column's names
        $fp = fopen($this->pathToFiles . $fileName, 'w');
        fputcsv($fp, $columns);

    foreach ($ent as $v) {
        fputcsv($fp, array($v->tax, $v->tap4, $v->grp5, $v->genus, $v->host, $v->country, v->date, $v->id, $v->reg_number));
}
fclose($fp);

}
Jun
22
1 year ago
Activity icon

Replied to Performing Concat On Where Clause

Thanks for your help!

Jun
21
1 year ago
Activity icon

Replied to Performing Concat On Where Clause

Hi Snapey,

I am trying to do the concatenate "first_name and last_name" of customer but it is throwing error as below, please can you help on this.

$orders = (new Order)->newQuery()->select('concat(customer_contacts.first_name," ",customer_contacts.last_name)')
                ->join('samples', 'orders.id', '=', 'samples.order_id' )
                ->join('assignments', 'samples.id', '=', 'assignments.sample_id' )
                ->join('customer_contacts', 'orders.customer_contact_id', '=', 'customer_contacts.id' )
                ->where('orders.id', '=', 1)                
                ->whereNotNull('customer_contacts.email')->first();
        }

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'concat(customer_contacts.first_name,\" \",customer_contacts.last_name)' in 'field list' (SQL: select `concat(customer_contacts`.`first_name,\" \",customer_contacts`.`last_name)` from `orders` inner join `samples` on `orders`.`id` = `samples`.`order_id` inner join `assignments` on `samples`.`id` = `assignments`.`sample_id` inner join `customer_contacts` on `orders`.`customer_contact_id` = `customer_contacts`.`id` where `orders`.`id` = 234877 and `assignments`.`team_id` = 4 and `customer_contacts`.`email` is not null limit 1)

Thanking in advanced. Mani

May
22
1 year ago
Activity icon

Replied to Laravel 5 Validation Request, How To Handle Validation On Update?

Hi bashy,

Thanks for helping on my above query, however I am still having the problem with this validation. Please can you help.

Many thanks for your time.

May
21
1 year ago
Activity icon

Replied to Laravel 5 Validation Request, How To Handle Validation On Update?

Sorry for the confusion .. reports is a array and it contains multiple values.

protected $rules = [

    'title'                                 =>'required|string|max:255',
    'slug'                                  =>"required|alpha_dash|min:5|max:255|unique:posts,slug",
    'image'                                 =>'sometimes|image', 
    'category_id'                       =>'required|integer',
    'reports'                               => 'sometimes',
    'reports.*.report_type_id'  => 'required|integer',

];

I have implemented as you suggested , however it is not working the validation for me, if I do not include the "report_type_id" as below:

"reports":[  
     {  
        "report":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus",        
        "test_id": 388594
     },
      {  
        "report":"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo",
        "report_type_id":1,
        "test_id": 388595
     },
     
      {  
        "report":"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo",
        "report_type_id":2,
        "test_id": 388596
     }
    
  ],

It is throwing database(MYSQL) error but it is not triggering the validation at all.

{
"message": "Undefined index: report_type_id",
    "status_code": 500,
}

Thank you for your great help!

May
18
1 year ago
Activity icon

Replied to Laravel 5 Validation Request, How To Handle Validation On Update?

Thanks for your reply. However I am still getting the below error message all the time. That means validation is triggering all the times. Please can you help on this.

{
    "message": {
        "reports": [
            "The reports field is required."
        ]
    }
}

Activity icon

Replied to API Resources

Books and Author have many-to-many relationships. Author have many books and Books have many Author, that's why Pivot table(author_book) is created. It holds author and books primary keys as foreign keys. Please see my Laravel model as below:

//author.php 
public function author()
{ 
    return $this->hasMany(AuthorBook::class); 
}

//book.php 
public function book() 
{ 
    return $this->hasMany(AuthorBook::class); 
}

//authorBook.php 
public function authors()
{ 
    return $this->belongsTo(Author::class); 
}

public function books()
{ 
    return $this->belongsTo(Book::class); 
}

Activity icon

Replied to API Resources

Book and author have got many-to-many relationship.

May
17
1 year ago
Activity icon

Replied to Generating PDFs From Laravel Views And Trying To Save In Mysql Database

Thanks anyway- I am using postman to generate the pdf though.

Activity icon

Replied to Generating PDFs From Laravel Views And Trying To Save In Mysql Database

Hi All,

I have managed to generate the pdf from the above code but I cannot open it and it was sent as an email attachment. Please can you help me on this.

May
16
1 year ago
Activity icon

Replied to Laravel 5 Validation Request, How To Handle Validation On Update?

protected $rules = [

    'title' =>'required|string|max:255',
    'slug' =>"required|alpha_dash|min:5|max:255|unique:posts,slug",
    'image' =>'sometimes|image', 'category_id' =>'required|integer',
    'reports.*.report_type_id' =>'required|integer',
];

I have tried as above but it did not work for me too.

Activity icon

Replied to Laravel 5 Validation Request, How To Handle Validation On Update?

protected $rules = [

    'title' =>'required|string|max:255',
    'slug' =>"required|alpha_dash|min:5|max:255|unique:posts,slug",
    'image' =>'sometimes|image', 'category_id' =>'required|integer',
    'reports.report_type_id' =>'required|integer'
];

The above request is validating but the reports(json payload) can have multiple entities as below:

{ "data":{ "generated_by": "foobar",

  "reports":[  
     {  
        "report":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus",
        "report_type_id":1,
        "test_id": 388594
     },
      {  
        "report":"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo",
        "report_type_id":1,
        "test_id": 388595
     },
     
      {  
        "report":"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo",
        "report_type_id":2,
        "test_id": 388596
     }
    
  ],
  

} }

Activity icon

Replied to Laravel 5 Validation Request, How To Handle Validation On Update?

Hi there,

In the below example the report is an array I want to write the rules to validate array Item i.e. report.id - is this possible to do it? if not please can you suggest me on this.

$rules = [ 'title' =>'required|string|max:255', 'slug' =>"required|alpha_dash|min:5|max:255|unique:posts,slug", 'image' =>'sometimes|image', 'category_id' =>'required|integer', 'report' =>'required' ];

Thanking in advanced!

May
13
1 year ago
Activity icon

Replied to API Resources

The above are my model examples...

How can I include book resources when I am creating author resources api?

May
10
1 year ago
Activity icon

Replied to Generating PDFs From Laravel Views

That's what I am doing right now. I want to save it to the database.

view()->share('lab',$data);
    $pdf = PDF::loadView('lab.test');
    return $pdf->download('test_'. $request['Id'] . '_lab.pdf');
Activity icon

Replied to Generating PDFs From Laravel Views And Trying To Save In Mysql Database

That's what I am doing right now. I want to save it to the database.

view()->share('lab',$data);
    $pdf = PDF::loadView('lab.test');
    return $pdf->download('test_'. $request['Id'] . '_lab.pdf');
Activity icon

Replied to Save PDF File With Dompdf

That's what I am doing right now. I want to save it to the database.

view()->share('lab',$data);
    $pdf = PDF::loadView('lab.test');
    return $pdf->download('test_'. $request['Id'] . '_lab.pdf');
Activity icon

Replied to Generating PDFs From Laravel Views

Hi Guys,

Is there anyway generated PDF file(from a Laravel View) can be saved in the database?

Activity icon

Started a new conversation Generating PDFs From Laravel Views And Trying To Save In Mysql Database

Hi all, I 've been using this library(https://github.com/barryvdh/laravel-dompdf) to generate PDF from a Laravel View and trying to save in the database.

Is there any methods to save the pdf in the database without saving in the file system?

Thanking in Advanced.

Activity icon

Replied to Save PDF File With Dompdf

Is there anyway it can be saved in the database?

May
09
1 year ago
Activity icon

Started a new conversation API Resources

Hi,

Please can you help on this- I am trying to to include book resources api when I am creating API resources for author. This two tables has many to many relationship.

Please see example as below:

//author.php public function author() { return $this-hasMany(AuthorBook::class); }

//book.php Public function book() { return $this-hasMany(AuthorBook::class); }

//authorBook.php Public function authors() { return $this->belongsTo(Author::class); }

Public function books() { return $this->belongsTo(Book::class); }

Feb
01
1 year ago
Activity icon

Replied to Truncates Text Data From SQL Server

Please can you help me on my previous post as above.

Jan
30
1 year ago
Activity icon

Replied to Truncates Text Data From SQL Server

Sorry for posting many times- I am unable to post sql query:

Yes, it is still truncating on retrieval of the results set. Please find the query I am running to retrieve the data in mssql server as below.

However I found the solution, it needs defining MSSQL server connection before executing the query. I.e use Illuminate\Support\Facades\DB;

DB::connection('mssqlMilan')->select('SET TEXTSIZE -1');

Which is not the ideal solution for me because every time I run this function/code TEXTSIZE needs to define before executing the query.

Is there a way to configure Laravel to automatically pull the entire data result without truncating it ?

Activity icon

Replied to Truncates Text Data From SQL Server

Which is not the ideal solution for me because every time I run this function/code TEXTSIZE needs to define before executing the query.

Is there a way to configure Laravel to automatically pull the entire data result without truncating it ?

Activity icon

Replied to Truncates Text Data From SQL Server

use Illuminate\Support\Facades\DB; DB::connection('mssqlMilan')->select('SET TEXTSIZE -1')

Activity icon

Replied to Truncates Text Data From SQL Server

Yes, it is still truncating on retrieval of the results set. Please find the query I am running to retrieve the data in mssql server as below.

Activity icon

Replied to Truncates Text Data From SQL Server

Sorry I am not able to post

Jan
27
1 year ago
Activity icon

Replied to Truncates Text Data From SQL Server

80,072 characters strings but it could be longer than that. Is there a way to configure Laravel5.2 to pull the entire text data for that field without truncating?

Activity icon

Replied to Truncates Text Data From SQL Server

Hi Sapey,

Thanks for your comments. I am querying as text value from mssql server but it is truncating before inserting to mysql database and not able to get whole text record value as a result set.

I was trying to SET TEXTSIZE to 2147483647 before executing the query in Larave 5.2. It did not work for me please need help.

Jan
26
1 year ago
Activity icon

Started a new conversation Truncates Text Data From SQL Server

When querying to get data from MSSQL database, its text field data is truncating, and not able to display in the website.

I am using both databases connection (as below) to fetch the data from mssql database, and dumping in mysql database.

'connections' => [

    'mssqlMilan' => array(
        'driver'   => 'sqlsrv',
        'host'     => env('DB_DIAGDOMERO_HOST', ''),
        'port'     => env('DB_DIAGDOMERO_PORT', ''),
        'database' => env('DB_DIAGDOMERO_DB', ''),
        'username' => env('DB_DIAGDOMERO_USERNAME', ''),
        'password' => $pwd,
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'   => '',

    ),

    'mysqlMilan' => [
        'driver' => 'mysql',
        'host' => env('DB_DIAG_HOST', ''),
        'port' => env('DB_DIAG_PORT', '3306'),
        'database' => env('DB_DIAG_DATABASE', ''),
        'username' => env('DB_DIAG_USERNAME', ''),
        'password' => $pwd,
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

],

I have also updated my php.ini file and it is set to (mssql.textlimit' , '2147483647' and 'mssql.textsize' , '2147483647') but no luck.

Please can you help.