jeudi 1 décembre 2016

Task Scheduling : Laravel 5.3

I am following this tutorial to schedule a function every minute. Below is my code.

class Kernel extends ConsoleKernel
{
    protected $commands = [
        'App\Console\Commands\Inspire',
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->call($this->WriteFile())->everyMinute();
    }

    protected function commands()
    {
        require base_path('routes/console.php');
    }

    private function WriteFile() {
        $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
        $txt = "John Doe\n";
        fwrite($myfile, $txt);
        fclose($myfile);
    }
}

I saw that the txt file is not showing the contents. i placed the txt file in public folder. Am I missing something?



via Chebli Mohamed

How to create a method inside of the blade file on Laravel 5.3

I recently started learning Laravel and I am still trying to figure it out. So, please bear in mind this before judging me :)

I am trying to find a way to rewrite this:

<a href=""></a>

with a method, so I wouldn't have to do Client::find() inside of the view.

I tried doing this:

private function getClientName($id) { $clientName = Client::find($id)->name; return view('campaigns.index', compact('clientName')); }

... in the controller and called the method inside of the view, but it didn't work, and I can't think of anything else right now.

Any suggestions? Thanks!



via Chebli Mohamed

Laravel 5.2 Query not working

Hi i am trying to get this query to work...

DB::select(DB::raw('select 
sum(case when outreach_links.status="Pending" and outreach_links.created_at >= :from and outreach_links.created_at <=:to then 1 else 0 end) as pp,
  sum(case when outreach_links.status="Approved" and outreach_links.start_date >= :from and outreach_links.start_date <=:to then 1 else 0 end) as aa, sum(case when outreach_links.status="Approved" then outreach_links.cost else 0 end) as cc, MONTH(outreach_links.created_at) month, MONTHNAME(outreach_links.created_at) month_name , YEAR(outreach_links.created_at) year from outreach inner join outreach_links on outreach.id = outreach_links.outreach_id where outreach.profile_id=:proid group by month, year', ["from" => $from, "to" => $to, "proid" => $pro_id]))->get();

and I am getting an error, I cant solve it any help??

Call to a member function get() on a non-object

any idea how to make this query work using get()?

Thanks



via Chebli Mohamed

DB::raw in Laravel takes long time

I've a Laravel 5.2 application, I need to make an advanced query to the database so I'm trying to use the DB::raw expression, mainly, my query is like this:

SELECT * FROM TableA AS s
        LEFT JOIN TableB AS l FORCE INDEX FOR JOIN (idx_1) 
        ON ((s.mid = l.mid) AND (l.id = 1))
        LEFT JOIN TableC AS f FORCE INDEX FOR JOIN (idx_C_1)"
        ON (s.mid = f.mid)
        LEFT JOIN TableD as bl FORCE INDEX FOR JOIN (idx_D_1)
        ON ((bl.ACid = s.ACid) AND ((bl.userid = 1) OR (bl.userid = -1)) AND (bl.type = 1))
        LEFT JOIN TableE AS wl FORCE INDEX FOR JOIN (idx_E_1)
        ON ((wl.sid = s.sid) AND ((wl.userid = 1) AND (wl.type = 2)))
        LEFT JOIN TableF AS gwl FORCE INDEX FOR JOIN (idx_F_1)
        ON ((gwl.sid = s.sid) AND ((gwl.userid = -1) AND (gwl.type = 2)))
        WHERE (bl.sid IS NULL)

So, it just get stucked in Laravel and doesnt show me a response, so I executed it in PHPmyAdmin and the response is very very fast. In Laravel I have this:

   $query=DB::select(DB::raw(TheQueryAbove))
            ->orderBy('s.reversestamp', 'asc')
            ->offset(0)
            ->limit(26)
            ->paginate(10);

So, why it takes so long? or how can I test it to find the cause? I already tried: dd(DB::select(DB::raw(TheQueryAbove)))->toSql(); with no success, it doesnt even get printed. Thanks!



via Chebli Mohamed

Laravel5 - artisan down command trying to access database?

I've deployied a project on a new server. When i issue

php artisan down

i get

[PDOException]
  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas
  sword: YES)

Why is it trying to access the database? Why root? I'm confused.



via Chebli Mohamed

How can I edit or extend the error message in laravel5.3?

i want to extend validation setting another field just like that:

return Validator::make($data, [

        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6|confirmed',
        'another_field' => 'validation'
    ]); 



via Chebli Mohamed

Laravel : Syntax error or access violation: 1055 Error

I want use WhereIn and Groupby in Same Query to fetch Result.

$loadids=explode("#@*",$reciptdet->loading_id);
$loadingdatas=DB::table('loading')->groupBy('vehicle_no')->whereIn('id',$loadids)->get();



via Chebli Mohamed