mardi 17 novembre 2020

How to get Expiry date flag from pivot table Joining the parent table grouped by parent_id

I have a parent table with jobs and a pivot table with job provider (boards) and expiry dates.

Adjob table

id:1, job_title: Experienced full stack developer, .. .. location:Europe is_active:1

Boards table

id:1, adjob_id:1, board_name:Adzuna, expiry_date:2020-12-20,

id:2 adjob_id:1, board_name:Seek, expiry_date:2020-11-10,

id:3, adjob_id:1, board_name:Jora, expiry_date:2020-11-25,

This is the query used

$ads= Adjob::select([
            'adjobs.id',
            'adjobs.response',
            'adjobs.post_date',
            'adjobs.job_title',
            'adjobs.created_by',
            \DB::raw('(CASE 
                    WHEN (boards.board_name = "Adzuna" && (NOW() < boards.expiry_date && datediff(expiry_date,NOW()) <= 7)) THEN "1" 
                    WHEN (boards.board_name = "Jora" && (NOW() < boards.expiry_date && datediff(expiry_date,NOW()) <= 7)) THEN "1" 
                    WHEN (boards.board_name = "Seek" && (NOW() < boards.expiry_date && datediff(expiry_date,NOW()) <= 7)) THEN "1" 
                    ELSE "0" 
                    END) AS expiry')
            ])
            ->leftJoin('boards', 'adjobs.id', 'boards.adjob_id')
            
            ->where([['adjobs.active',1]])
            ->groupBy('adjobs.id')
            ->get();                    

But it is only checking the first values (i.e) Adzuna expiry only, because it is grouped by Parent table id i.e adjobs.id. How to check all the three expiry date using above the query.



via Chebli Mohamed

Laravel migrate fresh specific migration

I'm trying to migrate some database tables in my Laravel application. I'm using a third party library https://github.com/spatie/laravel-schedule-monitor which seems to break and requires re-migrating when upgrading. If I run php artisan migrate:fresh locally it'll work just fine, but amongst all of my other migrations I don't want to overwrite and dump the data in my other tables in a production environment.

I want to migrate:fresh a specific migration...



via Chebli Mohamed

How to use composite primary key in laravel 8?

I didn't use the migration files because I have preexisting tables in the database, I want to know how to force laravel to use my composite primary key.if there is any method to override. The composite primary key is (Tel + number_str ) This is my function in the model :

public function saveData(){
  $response = new ResponseModel(); 
                //Primary key(Tel + number_str )
                $reponse->Tel = '0123456789';//---> the first key
                $reponse->number_str = '1'; //---> the second key
    
                $reponse->view = '0';  
                $reponse->channal = '0';
                $reponse->save();
}

when I execute I have this error: Yajra\Pdo\Oci8\Exceptions\Oci8Exception Error Code : 904 Error Message : ORA-00904: "ID": invalid identifier Position : 98 Statement : insert into "REPONSE" ("TEL", "number_str", "view", "channal ") values (:p0, :p1, :p2, :p3) returning "ID" into :p4 Bindings : [0772529403,1,0,0,0]



via Chebli Mohamed

lundi 16 novembre 2020

How to pass data id to modal?

i need to pass the dropdown id value once been selected. The id must be pass to modal.

This is my code for view :

<div class="panel panel-default">
    <div class="panel-heading">
        <h4></h4>
    </div>
    <div class="panel-body">
        <div class="form-horizontal">
            <label class="col-lg-2 control-label">{!! msg('lbl_education_level') !!}</label>
            <div class="col-lg-4">
                {!! Form::dropdown('education_level_id', $edulevelselection, '', 'class="select2-form edulevel"') !!}
            </div>
            <span>
                    {!! Form::buttonAdd('','#',[
                    'data-toggle' => 'modal',
                    'id' => 'education',
                    'data-title' => msg('lbl_new_academic_qualification'),
                    'data-target' => '#modal_global_form',
                    'data-url' => route('academic_qualification.create', [ 'id' => $staff_id] ),
                    'data-action' => route('academic_qualification.store'),
                    'data-size' => 'modal-lg',
                    'data-param' => '{ }'
                    ]) !!}
                </span>
        </div>
    </div>
</div>
@push('scripts')
<script type="text/javascript">

$('#education_level_id').change(function(e){
    var edulevelid = $('#education_level_id').val();
    console.log(edulevelid);
    $('#education').attr('data-param','{"education_level_id":'+edulevelid+'}');
})

</script>
@endpush

But the value i want is not show up, i do the dump() at the controller. it just show my id only. This is the dump i make on the controller:

enter image description here



via Chebli Mohamed

Why Laravel Sanctum SPA Authentication always keep the user logged in?

I used Laravel Sanctum SPA authentication. I can log out the user but I am wondering why is it that the user is still logged in even when I close the browser. I don't even implement the remember me function.



via Chebli Mohamed

How to send SMS using firebase in laravel

I am developing a laravel application,in which while user register, i want to send the registration code through SMS, i don't want to use any paid services.I heard about firebase free SMS gateway. Is there any option to send SMS through firebase



via Chebli Mohamed

Relation query undefined method

In my setting model class i have this

public function user()
    {
        return $this->hasMany('App\User');
    }

and in my user model class i have this

 public function settings()
    {
        return $this->belongsTo('App\settings', 'id');
    }

I tried both these queries, trying to get the user information but failed.

$data = DB::table('settings')
                        ->where('id', '=', $id)
                        ->get()
                        ->toArray();

and

$table = \App\settings::where('id', '=', $id);
        $query = $table->user()
                       ->get()
                       ->toArray();

I'm getting this error

Call to undefined method Illuminate\Database\Eloquent\Builder::user()

How do you do relation query? Sorry new to laravel here.



via Chebli Mohamed