ssquare

Member Since 2 Years Ago

Experience Points
5,750
Total
Experience

4,250 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
21
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.

  • Community Pillar

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

Level 2
5,750 XP
Dec
22
1 month ago
Activity icon

Replied to Laravel Excel Style With CSS Not Working While Exporting View

@snapey I have figured out that I need to include inline CSS for font-weight and color, but how could I add strkiethrough to any td.

And, I don't get which HTML tag you are referring to. If there is any better way to do it could you suggest it?

Dec
21
1 month ago
Activity icon

Replied to Laravel Excel Style With CSS Not Working While Exporting View

Any suggestions, I have not received a single reply :(

Dec
20
1 month ago
Activity icon

Started a new Conversation Laravel Excel Style With CSS Not Working While Exporting View

I am trying to export view using laravel Excel 3.1. While the export is working, I am not being able to style it.

My laravel Export looks as:

<?php

namespace App\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\RegistersEventListeners;
use Maatwebsite\Excel\Events\AfterSheet;

class MatrixExcelExport implements FromView, WithEvents
{
    use RegistersEventListeners;
    protected $data, $selected_data, $am_lists_only, $categories_list, $amenities_list, $affordable_list, $unit_type_list, $highlights_list, $non_unit;
    public function __construct($data, $selected_data, $am_lists_only, $categories_list, $amenities_list, $affordable_list, $unit_type_list, $highlights_list, $non_unit)
    {
        $this->data = $data;
        $this->selected_data = $selected_data;
        $this->am_lists_only = $am_lists_only;
        $this->categories_list = $categories_list;
        $this->amenities_list = $amenities_list;
        $this->affordable_list = $affordable_list;
        $this->unit_type_list = $unit_type_list;
        $this->highlights_list = $highlights_list;
        $this->non_unit = $non_unit;
    }

    public function view(): View
    {
        return view('admin.matrix._excel', [
            'data' => $this->data,
            'selected_data' => $this->selected_data,
            'am_lists_only' => $this->am_lists_only,
            'categories' => $this->categories_list,
            'amenities' => $this->amenities_list,
            'affordables' => $this->affordable_list,
            'unit_types' => $this->unit_type_list,
            'highlights' => $this->highlights_list,
            'non_unit' => $this->non_unit
        ]);
    }
}

And my _excel looks like this:

<?php
$impact = 0;
$negativeChanges = 0;
$positiveChanges = 0;
?>
<style>
    .strikethroughCell{
        text-decoration: line-through !important;
    }
    .table-text-center th,
    .table-text-center td{
        text-align: center !important;
    }
</style>
<table class="table-text-center">
    <thead>
        <tr>
            <th rowspan="2">Bldg</th>
            <th rowspan="2">Unit</th>
            <th rowspan="2">Floor</th>
            <th rowspan="2">Stack</th>
            @foreach($selected_data as $k => $v)
                <th colspan="{{count($v['amenities'])}}">
                    {{$v['category_name']}}
                </th>
            @endforeach
        </tr>
        <tr>
            @foreach($am_lists_only as $ak => $av)
                <th title="{{ $av }}">
                    <?php
                        if (strlen($av) > 15){
                            $av = substr($av, 0, 12) . '...';
                        }
                    ?>
                    {{ $av }}
                </th>
            @endforeach
        </tr>
    </thead>
    <tbody>
    @foreach($data as $k => $v)
        <?php
        if(count($v) == 0){
            continue;
        }
        $unit_cell_status  = '';
        $unit_note_class = '';
        $avail_status = '';

        if(trim($v[0]->unit_note) != ''){
            $unit_note_class = 'unit_note';
        }
        if(isset($v[0]->avail_status)){
            $avail_status = str_replace(' ','-',strtolower($v[0]->avail_status));
            if(!in_array($avail_status,$highlights)){
                $avail_status = '';
            }
        }
        $unit_type_id = NULL;
        if(!empty($v[0]->unit_type_id)){
            $unit_type_id = $v[0]->unit_type_id;
        }
        $unit_type_class = (in_array($unit_type_id, $unit_types))?"td-unit-type":"";

        ?>
        <tr id="ur_{{$v[0]->unit_id}}">
            <td data-search="{{ $v[0]->building_number }}">{{ $v[0]->building_number }}</td>
            <td data-search="{{ $v[0]->unit_id }}" data-unitid="{{$v[0]->unit_id}}" id="unitCell_{{$v[0]->unit_id}}" class="td-unit {{ $unit_note_class }} {{ $avail_status }} {{ $unit_type_class }}" xonclick="editUnit(1, {{ $v[0]->unit_id }}, {{ $v[0]->building_id }}); return false;">{{ $v[0]->unit_number }}</td>
            <td data-search="{{ $v[0]->floor }}">{{ $v[0]->floor }}</td>
            <td data-search="{{ $v[0]->stack }}">{{ $v[0]->stack }}</td>
            @foreach($am_lists_only as $ak => $av)
                <?php
                $amenity_val = "";
                $deleted_class = "";
                $negativeClass = "";
                $affordable = false;
                $text_class = '';
                $strikethrough_class = '';
                foreach($v as $vk => $vv){
                    if($ak == $vv->amenity_id){
                        if( (isset($categories[0]) && $categories[0] === "-1") || !empty(in_array($vv->category_id, $categories)) || !empty(in_array($vv->amenity_id, $amenities))) {
                            if(empty($vv->uav_deleted_at)){
                                $impact += $vv->amenity_value;
                                if($vv->av_status == 2){
                                    $text_class = 'text-updated';
                                    if($unit_cell_status == ''){
                                        $unit_cell_status = $text_class;
                                    }

                                    if($vv->initial_amenity_value != $vv->amenity_value){
                                        $diff = $vv->amenity_value - $vv->initial_amenity_value  ;
                                        if($diff > 0){
                                            $positiveChanges += $diff;
                                        }else{
                                            $negativeChanges += abs($diff);
                                        }
                                    }
                                }

                                if($vv->uav_status == 1){
                                    $text_class = 'text-added';
                                    $unit_cell_status = $text_class;
                                    if($vv->amenity_value != 0){
                                        if($vv->amenity_value > 0){
                                            $positiveChanges += abs($vv->amenity_value);
                                        }else{
                                            $negativeChanges += abs($vv->amenity_value);
                                        }
                                    }
                                }

                            }else{
                                $deleted_class = "td-deleted";
                                if($vv->amenity_value != 0){
                                    if($vv->amenity_value > 0){
                                        $negativeChanges += abs($vv->amenity_value);
                                    }else{
                                        $positiveChanges += abs($vv->amenity_value);
                                    }
                                }
                                $strikethrough_class = 'strikethroughCell';
                            }
                            $show_sum = true;
                            if($affordable == false && in_array($vv->amenity_id, $affordables) && empty($vv->uav_deleted_at)){
                                $affordable = true;
                            }
                            $amenity_val = $vv->amenity_value;
                            if($amenity_val < 0){
                                $amenity_val = "(".abs($amenity_val).")";
                                $negativeClass = 'text-negative';
                            }
                            if($deleted_class != ""){
                                $amenity_val = "<del>".$amenity_val."</del>";
                            }
                        }else{
                            if(empty($vv->uav_deleted_at)){
                                if($vv->av_status == 2){
                                    if($vv->initial_amenity_value != $vv->amenity_value){
                                        $diff = $vv->amenity_value - $vv->initial_amenity_value  ;
                                        if($diff > 0){
                                            $positiveChanges += $diff;
                                        }else{
                                            $negativeChanges += abs($diff);
                                        }
                                    }
                                }
                                if($vv->uav_status == 1){
                                    if($vv->amenity_value != 0){
                                        if($vv->amenity_value > 0){
                                            $positiveChanges += abs($vv->amenity_value);
                                        }else{
                                            $negativeChanges += abs($vv->amenity_value);
                                        }
                                    }
                                }
                            }else{
                                if($vv->amenity_value != 0){
                                    if($vv->amenity_value > 0){
                                        $negativeChanges += abs($vv->amenity_value);
                                    }else{
                                        $positiveChanges += abs($vv->amenity_value);
                                    }
                                }
                            }
                        }
                    }
                }
//                $str = ['<del>','</del>'];
//                $rplc =['-','-'];
//                $search_val = str_replace($str,$rplc,$amenity_val);

                ?>
                <td data-am_id="{{$ak}}" class="{{$strikethrough_class}} {{($affordable == true)?'affordable-unit':''}} {{$deleted_class}} {{$negativeClass}} {{ $text_class }}">
                    {!! $amenity_val !!}
                </td>
            @endforeach
        </tr>
    @endforeach
    </tbody>
</table>

Well, I want to center the text of all cells and want to add strikethrough to the text of those td with class strikethroughCell

Dec
17
1 month ago
Activity icon

Replied to Laravel Eloquent Relationships, Return Only Those Data Which Are Created Earlier Than The Calling Model

syntax error, unexpected '.', expecting :: (T_PAAMAYIM_NEKUDOTAYIM)

Dec
16
1 month ago
Activity icon

Started a new Conversation Laravel Eloquent Relationships, Return Only Those Data Which Are Created Earlier Than The Calling Model

I have a relationships:

    public function unitAmenityValues()
    {
        return $this->hasMany(
            'App\Models\UnitAmenityValue',
            'amenity_value_id',
            'amenity_value_id'
        );
    }

Tables:

reviews

id, amenity_value_id, created_at, updated_at , deleted_at.....

units_amenities_values

id, amenity_value_id, unit_id, uav_status, created_at, updated_at, deleted_at

Currently, am calling the counts of unitAmenityValues from review as:

$review = Review::->withCount(['unitAmenityValues'])
            ->where('property_id',$id)
            ->orderBy('id','desc')
            ->get();

Now, I am looking to create another eloquent relationship function as:

    public function olderUnitAmenityValues()
    {
        return $this->hasMany(
            'App\Models\UnitAmenityValue',
            'amenity_value_id',
            'amenity_value_id'
        )
	->where('created_at','<=','CREATED_AT DATE OF REVIEWS');
    }
Oct
13
3 months ago
Activity icon

Started a new Conversation How To Add Numbers At The End Of Newly Inserted Value If There Value Is Already Existed

Let's say I have a unique column property_name and I have already inserted a property let's say Abc Now, whenever I try to insert the same value I want it to be automatically saved as Abc (1).

Are there any inbuilt functions for this in laravel? If not, could you suggest me a clean way to achieve this?

Oct
08
3 months ago
Activity icon

Replied to ForceDelete Not Working

Could anybody give me a clue what should I start testing?

Oct
05
3 months ago
Activity icon

Replied to ForceDelete Not Working

while doing dd

Illuminate\Database\Eloquent\Collection {#1858
  #items: array:1 [
    0 => App\Models\Review {#1857
      #table: "reviews"
      #guarded: array:1 [
        0 => "id"
      ]
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:18 [
        "id" => 254
        "amenity_id" => null
        "category_id" => null
        "amenity_value_id" => 8073
        "unit_id" => null
        "new_amenity_value" => 10.0
        "old_amenity_value" => null
        "property_id" => 157
        "action" => 1
        "note" => null
        "multiple_units" => "["39306","39307"]"
        "status" => 1
        "created_by" => 9
        "reviewed_by" => null
        "created_at" => "2020-10-05 20:17:20"
        "updated_at" => "2020-10-05 20:17:20"
        "deleted_at" => null
        "units_count" => 2
      ]
      #original: array:18 [
        "id" => 254
        "amenity_id" => null
        "category_id" => null
        "amenity_value_id" => 8073
        "unit_id" => null
        "new_amenity_value" => 10.0
        "old_amenity_value" => null
        "property_id" => 157
        "action" => 1
        "note" => null
        "multiple_units" => "["39306","39307"]"
        "status" => 1
        "created_by" => 9
        "reviewed_by" => null
        "created_at" => "2020-10-05 20:17:20"
        "updated_at" => "2020-10-05 20:17:20"
        "deleted_at" => null
        "units_count" => 2
      ]
      #changes: []
      #casts: []
      #dates: array:1 [
        0 => "deleted_at"
      ]
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [
        "units" => Illuminate\Database\Eloquent\Collection {#1861
          #items: array:2 [
            0 => App\Models\Unit {#1901
              #table: "units"
              #guarded: array:1 [
                0 => "id"
              ]
              #dates: array:3 [
                0 => "created_at"
                1 => "updated_at"
                2 => "deleted_at"
              ]
              #connection: "mysql"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:14 [
                "id" => 39306
                "unit_number" => "207"
                "Unit_ID" => null
                "unit_code" => null
                "unit_type" => null
                "unit_sqft" => null
                "unit_rent" => null
                "unit_note" => null
                "stack" => "7"
                "floor_id" => 2219
                "building_id" => 623
                "created_at" => "2020-10-05 08:46:09"
                "updated_at" => "2020-10-05 08:46:09"
                "deleted_at" => null
              ]
              #original: array:16 [
                "id" => 39306
                "unit_number" => "207"
                "Unit_ID" => null
                "unit_code" => null
                "unit_type" => null
                "unit_sqft" => null
                "unit_rent" => null
                "unit_note" => null
                "stack" => "7"
                "floor_id" => 2219
                "building_id" => 623
                "created_at" => "2020-10-05 08:46:09"
                "updated_at" => "2020-10-05 08:46:09"
                "deleted_at" => null
                "pivot_review_id" => 254
                "pivot_unit_id" => 39306
              ]
              #changes: []
              #casts: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: array:1 [
                "pivot" => Illuminate\Database\Eloquent\Relations\Pivot {#1900
                  +incrementing: false
                  #guarded: []
                  #connection: null
                  #table: "review_unit"
                  #primaryKey: "id"
                  #keyType: "int"
                  #with: []
                  #withCount: []
                  #perPage: 15
                  +exists: true
                  +wasRecentlyCreated: false
                  #attributes: array:2 [
                    "review_id" => 254
                    "unit_id" => 39306
                  ]
                  #original: array:2 [
                    "review_id" => 254
                    "unit_id" => 39306
                  ]
                  #changes: []
                  #casts: []
                  #dates: []
                  #dateFormat: null
                  #appends: []
                  #dispatchesEvents: []
                  #observables: []
                  #relations: []
                  #touches: []
                  +timestamps: false
                  #hidden: []
                  #visible: []
                  #fillable: []
                  +pivotParent: App\Models\Review {#1811
                    #table: "reviews"
                    #guarded: array:1 [
                      0 => "id"
                    ]
                    #connection: null
                    #primaryKey: "id"
                    #keyType: "int"
                    +incrementing: true
                    #with: []
                    #withCount: []
                    #perPage: 15
                    +exists: false
                    +wasRecentlyCreated: false
                    #attributes: []
                    #original: []
                    #changes: []
                    #casts: []
                    #dates: array:1 [
                      0 => "deleted_at"
                    ]
                    #dateFormat: null
                    #appends: []
                    #dispatchesEvents: []
                    #observables: []
                    #relations: []
                    #touches: []
                    +timestamps: true
                    #hidden: []
                    #visible: []
                    #fillable: []
                    #forceDeleting: false
                  }
                  #foreignKey: "review_id"
                  #relatedKey: "unit_id"
                }
              ]
              #touches: []
              +timestamps: true
              #hidden: []
              #visible: []
              #fillable: []
              #forceDeleting: false
            }
            1 => App\Models\Unit {#1902
              #table: "units"
              #guarded: array:1 [
                0 => "id"
              ]
              #dates: array:3 [
                0 => "created_at"
                1 => "updated_at"
                2 => "deleted_at"
              ]
              #connection: "mysql"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:14 [
                "id" => 39307
                "unit_number" => "208"
                "Unit_ID" => null
                "unit_code" => null
                "unit_type" => null
                "unit_sqft" => null
                "unit_rent" => null
                "unit_note" => null
                "stack" => "8"
                "floor_id" => 2219
                "building_id" => 623
                "created_at" => "2020-10-05 08:46:10"
                "updated_at" => "2020-10-05 08:46:10"
                "deleted_at" => null
              ]
              #original: array:16 [
                "id" => 39307
                "unit_number" => "208"
                "Unit_ID" => null
                "unit_code" => null
                "unit_type" => null
                "unit_sqft" => null
                "unit_rent" => null
                "unit_note" => null
                "stack" => "8"
                "floor_id" => 2219
                "building_id" => 623
                "created_at" => "2020-10-05 08:46:10"
                "updated_at" => "2020-10-05 08:46:10"
                "deleted_at" => null
                "pivot_review_id" => 254
                "pivot_unit_id" => 39307
              ]
              #changes: []
              #casts: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: array:1 [
                "pivot" => Illuminate\Database\Eloquent\Relations\Pivot {#1860
                  +incrementing: false
                  #guarded: []
                  #connection: null
                  #table: "review_unit"
                  #primaryKey: "id"
                  #keyType: "int"
                  #with: []
                  #withCount: []
                  #perPage: 15
                  +exists: true
                  +wasRecentlyCreated: false
                  #attributes: array:2 [
                    "review_id" => 254
                    "unit_id" => 39307
                  ]
                  #original: array:2 [
                    "review_id" => 254
                    "unit_id" => 39307
                  ]
                  #changes: []
                  #casts: []
                  #dates: []
                  #dateFormat: null
                  #appends: []
                  #dispatchesEvents: []
                  #observables: []
                  #relations: []
                  #touches: []
                  +timestamps: false
                  #hidden: []
                  #visible: []
                  #fillable: []
                  +pivotParent: App\Models\Review {#1811}
                  #foreignKey: "review_id"
                  #relatedKey: "unit_id"
                }
              ]
              #touches: []
              +timestamps: true
              #hidden: []
              #visible: []
              #fillable: []
              #forceDeleting: false
            }
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #forceDeleting: false
    }
  ]
}
Activity icon

Replied to ForceDelete Not Working

same issue, Could DB::transaction be the issue??

Activity icon

Replied to ForceDelete Not Working

@a4ashraf you mean commenting all relationship? With that I won't be able to get the data at first.

Activity icon

Replied to ForceDelete Not Working

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Review extends Model
{
    use SoftDeletes;
    protected $table = 'reviews';

    protected $guarded = ['id'];
    protected $dates = ['created_at','updated_at'];

    /**===========
     * Relations
    =============*/

    /**
     * Return respected unit
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
//    public function unit()
//    {
//        return $this->belongsTo('App\Models\Unit');
//    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function property()
    {
        return $this->belongsTo('App\Models\Property');
    }

    /**
     * Return respected amenity
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function amenityValue()
    {
        return $this->belongsTo('App\Models\AmenityValue');
    }

    

    public function unitAmenityValues()
    {
        return $this->hasMany(
            'App\Models\UnitAmenityValue',
            'amenity_value_id',
            'amenity_value_id'
        );
    }

    Public function units()
    {
        return $this->belongsToMany('App\Models\Unit', 'review_unit');
    }

    public function amenity()
    {
        return $this->belongsTo('App\Models\Amenity');
    }
    public function category()
    {
        return $this->belongsTo('App\Models\Category');
    }


}

Review Schema

            $table->increments('id');
            $table->unsignedInteger('amenity_id')->nullable();
            $table->unsignedInteger('amenity_value_id')->nullable();
            $table->double('new_amenity_value')->nullable();
            $table->double('old_amenity_value')->nullable();
            $table->unsignedInteger('property_id')->nullable();
            $table->tinyInteger('action')->comment('1 => added, 2 => updated, 3 => deleted, 4 => Note Updated, 5 => Added ( New )');
            $table->text('unit_note')->nullable();
            $table->tinyInteger('status')->comment('1 => pending, 2 => accepted, 3 => rejected')->default(1);
            $table->unsignedInteger('created_by')->nullable();
            $table->unsignedInteger('reviewed_by')->nullable();
            $table->foreign('amenity_value_id')->references('id')->on('amenity_values')->onDelete('set null');
            $table->foreign('property_id')->references('id')->on('properties')->onDelete('set null');
            $table->foreign('created_by')->references('id')->on('users')->onDelete('set null');
            $table->foreign('reviewed_by')->references('id')->on('users')->onDelete('set null');
            $table->foreign('property_id')->references('id')->on('properties')->onDelete('cascade');
            $table->timestamps();

Pivot table schema

        Schema::create('review_unit', function (Blueprint $table) {
            $table->unsignedInteger('review_id');
            $table->unsignedInteger('unit_id');
            $table->foreign('review_id')->references('id')->on('reviews')->onDelete('cascade');
            $table->foreign('unit_id')->references('id')->on('units')->onDelete('cascade');
            $table->unique(['review_id', 'unit_id']);
        });
Activity icon

Replied to ForceDelete Not Working

@a4ashraf I think to get returns Object, isn't it?? By the way I have alsi tried with::

Review::where('id',$tv->id)->forceDelete()` as well, but with no success. Each items on the loop is object like this:

<pre>Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [0] => App\Models\Review Object
                (
Activity icon

Started a new Conversation ForceDelete Not Working

       	DB::transaction(function ()use($request,$uav_rows_with_amenity_and_units,$amenity_value,$property_id) {
//others code


    $to_be_deleted_reviews = Review::whereHas('units', function ($query) use ($after_start_unit_ids,$request) {
        $query->whereIn('units.id', $after_start_unit_ids);
    })->withCount('units')
        ->with('units')
        ->where('action',1)
        ->where('amenity_value_id',$request->av_id)
        ->where('property_id',$property_id)
        ->where('status',1)
        ->get();

    foreach($to_be_deleted_reviews as $tk => $tv){
        if($tv->units_count == $tv->units()->count()){
		echo "equal";
            $tv->forceDelete();
        }else{
            $tv->units()->detach($after_start_unit_ids);
        }
    }

})

Here, forceDelete is not working, it clearly echo "equals" but still didn't delete the row. However, it deletes related data on pivot tablereview_unit table.

Sep
05
4 months 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
4 months 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???