ssquare

ssquare

Member Since 1 Year Ago

Experience Points
3,600
Total
Experience

1,400 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
6
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 1
3,600 XP
May
15
1 month ago
Activity icon

Started a new Conversation Access Variable Across Multiple View

I am loading a view and later returning it as a JSON to the frontend, and loading that data directly into the view. This looks like:

##controller

	foreach($grouped as $gk => $data){
            $body = \View::make('admin.floor-stack._table')
                ->with('data',$data)
		->render();
		$body_str =  $body_str .$body
	}
	return response()->json([
		'body'	=> 	$body_str 
	]);

##_table

//after other calculations
$val = xxx

##frontend

$('#tableDiv').html('resp.body')

As you can see, each _table view will possess $val and my requirement is that I need to sum these $val from all _table that loaded in that foreach loop.

Apr
17
2 months ago
Activity icon

Replied to Import CSV File, Remove Empty Rows And Export It Immediately Without Storing It Into Database - Laravel Excel

@bobbybouwmann any other hacks or suggestions to make this workout. I am open to the suggestion of some other package as well.

Activity icon

Replied to Import CSV File, Remove Empty Rows And Export It Immediately Without Storing It Into Database - Laravel Excel

@bobbybouwmann I have done as you mentioned. However, still the same issue.

Also, my main issue is not about filtering. As even with my old method it is filtering empty rows. However, it is not forcing to download.

So far, my guess is that on the documentation it has mentioned that the array function of Import class would never return anything. Could that be the reason for not downloading CSV file?

Apr
16
2 months ago
Activity icon

Started a new Conversation Import CSV File, Remove Empty Rows And Export It Immediately Without Storing It Into Database - Laravel Excel

I am trying to remove all the empty rows from a csv and make it downloadable. In this process, there is no involvement of database/model.

My flow looks like:

  1. Import csv file.
  2. Filter empty rows.
  3. Export the data after all the empty rows are removed.

My code looks like:

#Controller

    public function formatCSV()
    {
        $path = storage_path('app/files/') . 'example.csv';
        Excel::import(new FormatCSV, $path);
    }

#app/Imports/FormatCSV

<?php


namespace App\Imports;


use App\Exports\ExportFormattedCSV;
use App\Http\Services\AmenityService;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Excel;

class FormatCSV implements ToArray, WithChunkReading
{
    private $table,$service,$model;
    public function __construct()
    {
        $this->service = new AmenityService();
    }
    public function array(Array $rows)
    {   $rec_arr = array();
        foreach ($rows as $row)
        {
            $rec_arr[] = array_values($row);
        }
        $records_arr = $this->service->trimArray($rec_arr);

        $export = new ExportFormattedCSV($records_arr);
        //print_r($export);
        return Excel::download($export, 'csv.csv');
    }

    public function chunkSize(): int
    {
        return 10;
    }

}

#app/Exports/ExportFormattedCSV

<?php


namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray;

class ExportFormattedCSV implements FromArray
{
    protected $data;

    public function __construct(array $data)
    {
        $this->data = $data;
    }
    public function array(): array
    {
        return $this->data;
    }

}

With this code it does nothing, shows blank at the end.

However, if I uncomment the line print_r($export)

It shows data as:

App\Exports\ExportFormattedCSV Object
(
    [data:protected] => Array
        (
            [0] => Array
                (
                    [0] => First Name
                    [1] => Last Name
                    [2] =>  Roll No
                )

            [1] => Array
                (
                    [0] => Ram
                    [1] => Patel
                    [2] => 1
                )

            [2] => Array
                (
                    [0] => Rajuv
                    [1] => Roy
                    [2] => 2
                )

            [3] => Array
                (
                    [0] => Sunny
                    [1] => Deol
                    [2] => 5
                )

            [4] => Array
                (
                    [0] => Akshya
                    [1] => Kumar
                    [2] => 6
                )

            [5] => Array
                (
                    [0] => Amir Khan
                    [1] => 7
                    [2] => 
                )

            [6] => Array
                (
                    [0] => Salman
                    [1] => Khan
                    [2] => 9
                )

            [7] => Array
                (
                    [0] => Bobby
                    [1] => Deol
                    [2] => 10
                )

        )

)

The File I am testing is example.csv

First Name,Last Name, Roll No
Ram,Patel,1
Rajuv,Roy,2
,,
Sunny,Deol,5
Akshya,Kumar,6
Amir Khan,7
,,
Salman,Khan,9
Bobby,Deol,10,
Barun,Dhawan,11
,,
Virat,Kohli,13
Rohit,Sharma,14

And trimArray function :

    public function trimArray($arr)
    {
        $final = array();

        foreach($arr as $k => $v)
        {
            if(array_filter($v)) {
                $final[] = $v;
            }
        }

        return $final;

    }
Apr
07
2 months ago
Activity icon

Started a new Conversation Laravel Got Stuck After Login. Laravel 5.8

I have done following:

Go to Login Page: amenity.local/login (or if I enter amenity.local it will redirect me to amenity.local/login) and after hitting enter the fav-icon shows loading forever and it got stuck there no results, no error, no timeout, nothing.

However, I could login with following cases:

  1. If I am already logged in and if I logged out. This will opens amenity.local/login page. Again, this time I could logged in easily without any hassle.

  2. If I am already logged in and then if I tried to access amenity.local/login then it will redirect to amenity.local/admin/property directly without showing login page.

But, As I have already mentioned, if I enter amenity.local/login in new page and enter credentials, then it stuck there forever. However, if I hit F5 (refresh) the page then it loads amenity.local/admin/property.

Login Controller

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/admin/property';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }


}

RedirectIfAuthenticated

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/admin/property');
        }
        return $next($request);
    }
}

Route

Auth::routes(['verify' => true]);

Route::get('/', function () {
    return redirect()->route('property.index');
});

Route::group(['middleware' => ['auth','verified']], function() {
    Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () {
    	Route::resource('property','PropertyController')->except(['create']);
    });
});  

route:list

| GET|HEAD | /  			 |   			  | Closure | web  
| GET|HEAD | admin/property  | property.index | App\Http\Controllers\Admin\[email protected] |verified   
| POST     | login 			 | 				  |App\Http\Controllers\Auth\[email protected] | web,guest