ssquare

ssquare

Member Since 2 Years Ago

Experience Points
3,860
Total
Experience

1,140 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,860 XP
Sep
05
3 weeks ago
Activity icon

Replied to Best Way To Send Validation Requests To Post Route

@snapey even with retirect()->route('routeName',compact(data)),it is passing data on the URL. This might trigger URL too long on some cases Any suggestion how to tackle this?

One way is ->with('data' => $data). But is there any other way than this? So that I could retrieve data other than using Session variables

Activity icon

Replied to Best Way To Send Validation Requests To Post Route

@snapey any suggestions on how to do this?? Currently, it's working as follows:

public function fieldMapping(Request $request){
//get request details

//get details and retrieve data from a CSV columns

//return field_mapping's view
}

view (fieldMapping)

//show form with the details
//submit to mapUB

mapUB function

public function mapUB has shown in question

By the way, I could have changed fieldMapping to GET requests, however, it is more than likely to trigger URL parameters too long

Activity icon

Started a new Conversation Best Way To Send Validation Requests To Post Route

Hi, I have routes as follows:

Route::post('availability/sub/field-mapping',['as' => 'availability.fieldMapping','uses' =>'[email protected]']);
Route::post('availability/sub/map-ub',['as' => 'availability.mapUB','uses' =>'[email protected]']);

Now inside mapUB, I have request validation.

public function mapUB(Request $request){
$required_all = array('unit_number','status');
$required_all_or_none = [];
$rules = [
    'row' => [new RequiredCSVColumn($request->additional_field,$required_all), new EitherBothOrNone($request->additional_field,$required_all_or_none)],
    'additional_field' => [new AdditionalFieldValidate()],
    'mapping_template_name' => ['required_with:saveMapping', new UniqueTemplatePerCompany($property->company_id)],
];

$customMessages = [
    'mapping_template_name.required_with' => 'The Mapping Template Name cannot be blank (if you want to save it).',
    'mapping_template_name.required_without' => 'The Mapping Template Name is required'
    ];

$this->validate($request, $rules, $customMessages);

....
....
....
   return view('admin.availability.map_ub',compact('filename','header_row','property','fieldMappingDetails','unitNumbers'));

}

Now whenever mapUB validation fails it will try to redirect to field mapping with errors, but with the GET method, and this will trigger errors because there no GET method for that.

To handle this one idea is using the match['GET','POST'] route however it will still throw an error because some parameter went missing.

Next, What I could do is, at first submit form with ajax, check the validation, and returns back. And, on ajax success submit the form directly. On this method, I need to send 2 requests. So, what is the best way to tackle this situation?

Sep
01
3 weeks ago
Activity icon

Replied to Laravel Storing Data By Cutting The Length Of The String

I think it will do the job, but is it possible to throw the error automatically like from the database not allowing to storing by cutting the data? Because I don't want to check the length for each column and each row because one CSV file might have thousands of rows.

Activity icon

Replied to Laravel Storing Data By Cutting The Length Of The String

Is there any way to do this other than this? I am storing data to the database using a CSV file with the help of the CSVleague library. I am performing this in a try catch block as:

try{
Model::firstOrCreate(
	[
	'amenity_name' => ($property_arr['amenity_name'] != '')?trim($property_arr['amenity_name']):NULL,
         'category_id' => (isset($this->data['map_cat_arr'][$property_arr['amenity_name']]))?$this->data['map_cat_arr'][$property_arr['amenity_name']]:NULL,
         'property_id' => $property->id
       ],
	[
		//other remaining col
	]

)	
}catch (\Exception $e) {
        $this->error_arr[$prop_id][] = $e->getMessage();
	$this->error_row_numbers[$prop_id][] = $this->data['row_value'];
}
Activity icon

Started a new Conversation Laravel Storing Data By Cutting The Length Of The String

I have column varchar (191), and I tested it with literally very long data than it can hold. But, surprisingly its not throwing error like Data too long. Instead, it is storing data by cutting the data to the length which it can hold.

Is there any way to trigger this error??

Could it be because of this default string lenght Schema::defaultStringLength(191); on AppServiceProvider???

Jul
22
2 months ago
Activity icon

Replied to Unable To Alter Foreign Column From Nullable To Not Null In Laravel Migration

@vincent15000 I had already deleted all the rows which have null value as:

       AmenityPricingReview::whereNull('unit_id')
                            ->orWhereNull('building_id')
                            ->orWhereNull('property_id')
                            ->withTrashed()
                            ->forceDelete();

In fact, I had tried by dropping all datas from amenity_pricing_reviews as well, but with no success.

Activity icon

Started a new Conversation Unable To Alter Foreign Column From Nullable To Not Null In Laravel Migration

I want to alter the nullable column to not nullable. Using: laravel 5.8

I have a table with unit_id, building_id and property_id as nullable. Now, I want to update it to not null. However, the migration is returning following error:

 SQLSTATE[HY000]: General error: 1832 Cannot change column 'building_id': used in a foreign key constraint 'amenity_pricing_reviews_building_id_foreign' (SQL: ALTER TABLE
 amenity_pricing_reviews CHANGE unit_id unit_id INT UNSIGNED NOT NULL, CHANGE building_id building_id INT UNSIGNED NOT NULL, CHANGE property_id property_id INT UNSIGNED NOT NULL, CHANGE dom dom VARCHAR(191) CHA
RACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`)

And my schema looks like:

    public function up()
    {
        Schema::table('amenity_pricing_reviews', function (Blueprint $table) {

            $table->dropForeign(['unit_id','building_id','property_id']);
            $table->unsignedInteger('unit_id')->nullable(false)->change();
            $table->unsignedInteger('building_id')->nullable(false)->change();
            $table->unsignedInteger('property_id')->nullable(false)->change();
            $table->foreign('unit_id')
                ->references('id')
                ->on('units');
            $table->foreign('building_id')
                ->references('id')
                ->on('buildings')
                ->onDelete('cascade');
            $table->foreign('property_id')
                ->references('id')
                ->on('properties')
                ->onDelete('cascade');
            $table->string('dom')->nullable()->change();
        });
    }

This is how I had created these columns on first time:

$table->unsignedInteger('unit_id')->nullable();
$table->foreign('unit_id')->references('id')->on('units')->onDelete('cascade');
$table->unsignedInteger('building_id')->nullable();
$table->foreign('building_id')->references('id')->on('buildings')->onDelete('cascade');
$table->unsignedInteger('property_id')->nullable();
$table->foreign('property_id')->references('id')->on('properties')->onDelete('cascade');
            
Jul
14
2 months ago
Activity icon

Started a new Conversation Laravel Pusher Error

I am running pusher via a queue, it just changes the status like running to completed.

It was working before, but recently I had updated composer to the new version and install new laravel installer.

Now, it is showing weird error, I could not figure this out what might be wrong here.

Illuminate\Broadcasting\BroadcastException in D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php:119
Stack trace:
#0 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastEvent.php(48): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'amenity-uploade...', Array)
#1 [internal function]: Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\PusherBroadcaster))
#2 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#3 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#5 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#6 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#7 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#8 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#9 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#10 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent), false)
#11 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#12 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(337): Illuminate\Queue\Jobs\Job->fire()
#13 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(283): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#14 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#15 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(102): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#16 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#17 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#18 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#19 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#20 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#21 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#22 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Console\Command.php(183): Illuminate\Container\Container->call(Array)
#23 D:\wamp64\www\amenity\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#24 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Console\Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#25 D:\wamp64\www\amenity\vendor\symfony\console\Application.php(1012): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 D:\wamp64\www\amenity\vendor\symfony\console\Application.php(272): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 D:\wamp64\www\amenity\vendor\symfony\console\Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Console\Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 D:\wamp64\www\amenity\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 D:\wamp64\www\amenity\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 {main}
May
14
4 months 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
5 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.

Apr
16
5 months ago
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?

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
5 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