sanainfotech

sanainfotech

Member Since 3 Years Ago

London

IT Consultant at Rescue My Properties

Experience Points 3,860
Experience Level 1

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 28
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

10 Jun
3 years ago

sanainfotech started a new conversation Where Condition To Get Pass 30 Days Worth Of Records

Hi

I have a date column in the database with varchar datatype stored as d-m-Y. In my where condition I am trying to fetch records for past 30 days only.

$backdate = Carbon::parse('-30 days')->toDateString(); $date30DaysBack = Carbon::parse($backdate)->format('d-m-Y'); $adverts = DB::table('adverts') ->where(DB::raw('STR_TO_DATE(instances.date,"%d-%m-%Y")'), '<=',$date30DaysBack)

15 Apr
3 years ago

sanainfotech started a new conversation Using Join Query With Adding Array In Where Condition

Using join query with where condition. But the tricky part is in the where condition how to access any array object. This array object is the value from another query. See query as below.

$adverts = DB::table('adverts')->
->where('advertiser.advertiser_id',$input);
get();

I got the result as needed, Now, how to write a query to join another table with the same list of value from $adverts->a_id.

Another table "advertsStorage" also have the column field as a_id. So i need to have all

I tried foreach as below did'nt work

foreach($adverts-> as $advert)
$adverts[] = DB::table('advertsStorage')
->where('a_id', '=', $advert->a_id)
->get();
04 Apr
3 years ago

sanainfotech left a reply on How To Write This Query With Multiple Select Statment

Finally, Thanks to everyone. I managed to get Laravel Eloquent way.

 $adverts =  DB::table('adverts')
                    ->select(DB::raw('(SELECT MAX(instances.date) FROM instances WHERE instances.ad_uid = adverts.ad_uid) AS Last_seen_date , adverts.*'))
                    ->whereIn('domain', function($query) use ($input)
                    {
                        $query->select(DB::raw('domains.domain'))
                        ->from('advertiser_domains')
                        ->join ('domains', 'advertiser_domains.domain_id', '=', 'domains.id')
                        ->where('advertiser_domains.advertiser_id',$input);
                    })
                    ->get();

sanainfotech left a reply on How To Write This Query With Multiple Select Statment

Thanks, @donkfather , Wanted to know Laravel way!

sanainfotech started a new conversation How To Write This Query With Multiple Select Statment

I would like to know how the write below sql query in laravel 5.2

I have id coming from end user

$input = Input::get('fullname');// get id from drop down list to serach by id
select * from adverts where domain in (
select domains.domain from advertiser_domains 
join domains on advertiser_domains.domain_id = domains.id 
where advertiser_domains.advertiser_id = $input);

01 Apr
3 years ago

sanainfotech left a reply on If Condition To Check Value 3 Column Of Table

I used larave orWhere.. work perfectly fine

/*
     * $value 0 = partially complted
     * $value 1 = Fully compeleted
     * $value 2 = Uncompelted
     */
    public function filterClassifcation(){
        if(Request::ajax()){    
            $value = Request::get('value');
            if($value==0){
                
                 $adverts = Adverts::where('a_id','!=',1)
                            ->where('strategy_id','=',1)
                            ->orWhere('product_id','=',1 )
                            ->orWhere('asset_id','=',1)->paginate(15);
                return view('cadmin.filterClassificationTable',compact('adverts')) ;
                
            }elseif($value==1){
                 $adverts = Adverts::where('a_id','!=',1)
                            ->where('strategy_id','=',1)
                            ->where('product_id','=',1)
                            ->where('asset_id','=',1)->paginate(15);
                 return view('cadmin.filterClassificationTable',compact('adverts')) ;
                
            }else{
                $adverts = Adverts::where('a_id','!=',0)
                            ->where('strategy_id','=',0)
                            ->where('product_id','=',0)
                            ->where('asset_id','=',0)->paginate(15);
                return view('cadmin.filterClassificationTable',compact('adverts')) ;
            }
              
           
        }
        
        
       
    }

sanainfotech started a new conversation If Condition To Check Value 3 Column Of Table

I am asking user to select from drop down what list of date user wants to view as below

I taking that value form the enduser sending to my controller methos as below.


     /*
     * $value 0 = partially complted
     * $value 1 = Fully compeleted
     * $value 2 = Uncompelted
     */
    public function filterClassifcation(){
        if(Request::ajax()){    
            $value = Request::get('value');
            if($value==0){
                // what can go hear
            }elseif($value==1){
                 $adverts = Adverts::where('a_id','!=',1)
                            ->where('strategy_id','=',1)
                            ->where('product_id','=',1)
                            ->where('asset_id','=',1)->paginate(15);
                
            }else{
                $adverts = Adverts::where('a_id','!=',0)
                            ->where('strategy_id','=',0)
                            ->where('product_id','=',0)
                            ->where('asset_id','=',0)->paginate(15);
            }
                  
        }
                      
    }
     

It was easy to check if 3 column has a value of 0 or 1

But how to check either of the column can be 0 or 1 to display, ignoring fully completed or fully uncomplted

I would like to run if condition to check the value of 3 column in one table.

30 Mar
3 years ago

sanainfotech started a new conversation Best Way To Manage Different Multiple Routes

My application I am using lots of GET and POST method in my routes as below,

Route::post('cadmin','CadminController@findAction');
    Route::get('cadmin','CadminController@index');
    Route::get('newClassification','CadminController@newClassification');
    Route::get('classifyAdverts','CadminController@classifyAdverts');
     Route::post('getAdverts','CadminController@getAdverts');  
     Route::post('updateClassification','CadminController@updateClassification');
    Route::post('cadminGetRegion','CadminController@cadminGetRegion');
    Route::post('addProductName','CadminController@addProductName');
    Route::post('addAssetName','CadminController@addAssetName');
    Route::post('addStrategyName','CadminController@addStrategyName');
    Route::get('mergeMultipleAdverts','CadminController@mergeMultipleAdverts');
    Route::post('mergeMultipleAdverts','CadminController@mergeMultipleAdverts');
    Route::post('mergeSelectedAdverts','CadminController@mergeSelectedAdverts');
    Route::get('mergeInstances','CadminController@mergeInstances');
    Route::post('mergeInstances','CadminController@mergeInstances');
    Route::post('getInstances','CadminController@getInstances');
    Route::get('deleteNoLanding','CadminController@deleteNoLanding');
    Route::post('deleteNoLanding','CadminController@deleteNoLanding');

I would like to know what is the best way to assign these kind of route?

21 Mar
3 years ago

sanainfotech started a new conversation Filtering Data Using Drop-down OnChange Event

I have a table name "domains" with column "state" type boolean value 0 or 1.

I have listed all adverts where state value = 0 in my controller as below

public function newdomain(){        
      $domains = DB::table('domains')->where('state' ,'=', 0)->get();        
        $advertisers = DB::table('advertisers')->get();         
        return view('admin.newdomain',compact('domains','advertisers'));
    }

On my view on the top of dataTable list, I have added a form with dropdown to select as below

{!! Form::open(array('url' => 'newdomain'))!!}
                                    <div class="form-group">
                                        <label for="">Select from the options</label>
                                        <select class="form-control input-sm" id="state" name="state" onchange="state()">
                                            <option value=""></option>
                                            <option value="0">Ignored</option>
                                            <option value="1">Not Ignored</option>
                                        </select>
                                    </div>                                    
                                    <div class="form-group">
                                        <button class="btn btn-primary" type="submit">Filter</button>                                        
                                    </div>
                                    {!! Form::close()!!}

I would like to Regenerate data table list based on the dropdown value selected.

I have been suggested to use Ajax, As i am new to JavaScript and jQuery, Please help me out

JavaScript:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
  <script>
      $( "#state" ).change(function() 
  {
    //
    });
  });
    </script>

What must go in my controller method newdomain()?

15 Mar
3 years ago

sanainfotech started a new conversation Max(date) Sql Query In Laravel 5.2

hi, I just wonder how to use below MySQL query in laravel eloquent.

SELECT MAX(date) AS "Last seen date" FROM instances WHERE ad_id =1

I have column date in instance table .

I would like to select the latest date from that table where ad_id =1

14 Mar
3 years ago

sanainfotech started a new conversation Using Model And Relation

What is the code for sql query below using model and relations

$advertisers = DB::table('advertisers')
            ->join('adverts', 'adverts.a_id', '=', 'advertisers.u_id')           
            ->select('advertisers.fullname')
            ->get();

Model Advertisers

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Advertisers extends Model
{
    protected $table = 'advertisers';
    
    
    public function adverts()
    {
            return $this->hasMany('App\Adverts');
    }
    
}


Model Adverts

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Adverts extends Model
{
    protected $table = 'adverts';
    
    
    public function advertisers()
    {
            return $this->belongsTo('App\Advertisers');
    }
    
}

11 Mar
3 years ago

sanainfotech left a reply on Redirect User After Login Based On Level Mentioned In Users Table

Hi @gocanto , can you elaborate more , where to add this method, and how will this check the user level, sorry new to laravel

sanainfotech started a new conversation Redirect User After Login Based On Level Mentioned In Users Table

I am using laravel 5.2 In my user table I have added extra column level. I would to redirect users based on the level when they login. User table

id | Name | email                       | password | level |
1  |  john   | john@john.com  | *********  |  1        |
1  |  jane| jane@jane.com  | *********  |  2        |

I dont want to apply roles and permission just want to redirect based on the level.

10 Mar
3 years ago

sanainfotech started a new conversation Dependency File Like Css, Javascipt Not Working

Hi I have all my CSS and JavaScript files are in public folder. My view layout

View

- Layouts
  -  head.blade.php
  -  header.blade.php
  - footer.blade.php
- Advert
   - index.blade.php
   - advertiserShow.blade.php

My index.blade.php working fine with all css and javascript file. but in advertiserShow.blade.php

Just wondering Is this is the right way. what might be the error one is working not another?

09 Mar
3 years ago

sanainfotech left a reply on The SQL SELECT DISTINCT Statement

Hi @tykus_ikus

I would like to display distinct value and ignor any row with empty value How can I achieve in laravel 5 using model - elequent this as below

SELECT DISTINCT meta_value 
FROM `wp_postmeta` 
WHERE meta_key = "aaa" AND meta_value != "";

sanainfotech left a reply on The SQL SELECT DISTINCT Statement

Hi @tykus_ikus

I want to populate distinct value from only one column of the table.

SELECT DISTINCT `ad_advertiser` FROM `adverts`

sanainfotech started a new conversation The SQL SELECT DISTINCT Statement

Hi I want to run a query just give me value with no duplicate.

What would be the query in laravel 5 using eloquent.

SQL query:

SELECT DISTINCT column_name
FROM table_name;

sanainfotech left a reply on Landing Page To Be Login Page

I am using Laravel 5. just made Authentication with command as below

php artisan make:auth

sanainfotech left a reply on Landing Page To Be Login Page

Call controller worked for me

Route::get('/', function () {
    return Redirect::action('Auth\AuthController@showLoginForm');
});

Wonder why url didn't worked?

sanainfotech left a reply on Landing Page To Be Login Page

Got this error

Missing argument 1 for Illuminate\View\View::withErrors(), called in C:\xampp\htdocs\centralDB\app\Http\routes.php on line 15 and defined

sanainfotech left a reply on Landing Page To Be Login Page

Hi @Prez I tried that , Its gives me error as

Undefined variable: errors (View: C:\xampp\htdocs\centralDB\resources\views\auth\login.blade.php)

sanainfotech started a new conversation Landing Page To Login Page

Hi I am trying basic think, I would like when user enter the web address the home page must be auth/login page.

My Route

Route::get('/', function () {
    return view('login');
});

Its giving me error as :

InvalidArgumentException in FileViewFinder.php line 137:
View [login] not found.
22 Feb
3 years ago

sanainfotech left a reply on Query To Check If User_id Exist In Multiple Tables

@boobybouwmann

Hi , when I am in current form, for ex:-profiledetails

 public function store(CreatingProfileRequest $request)
  {
     //Profiledetails::create($request->all()); // with out relation
    $input =   new Profiledetails($request->all());
    
    Auth::user()->profiledetailsHasOne()->save($input);      
    $this->formCheck();
  }

public function formCheck(){      
       $user = Auth::user();       
       $user->load(['profiledetailsHasOne','educationHasOne','occupationHasOne','maritalHasOne','parentsHasOne','addressHasOne']);
       
       if (! $user->profiledetailsHasOne) {
            return redirect('parents/create');
        } 
        elseif (! $user->educationHasOne) {
            return redirect('parents/create');
        }
        elseif (! $user->occupationHasOne) {
            return redirect('occupation/create');
        }
        elseif (! $user->maritalHasOne) {
            return redirect('marital/create');
        } 
        elseif (! $user->parentsHasOne) {
            return redirect('parents/create');
        }
        elseif (! $user->addressHasOne) {return redirect('address/create');}            
        else{ return redirect('profile');}      
    }

sanainfotech left a reply on Query To Check If User_id Exist In Multiple Tables

@boobybouwmann Thanks, yes I have relation between the tables setup,

In AuthController

protected $redirectTo = '/profiledetails/create';

In What controller do I need to add your mentioned code

sanainfotech started a new conversation Query To Check If User_id Exist In Multiple Tables

I am having 4 tables in my database,

users profiledetails has FK user_id physical has FK user_id education has FK user_id

Scenario 1 Signup are stored in users table After successfully signed up , They need to go through registration process. Registration process is 3 different form for 3 different table as mention above.

Scenario 2 User has logged in, who is already signed up user I would like to check weather he has filled up all the form or not, if not redirect to specific form, To check loop to check all table has user_id.

Hope make sense.

sanainfotech left a reply on Join Query In Laravel With Data Manipulation Send To View

@boobybouwmann Can you show me an example please in the code!

sanainfotech started a new conversation Join Query In Laravel With Data Manipulation Send To View

I am having 2 tables, users and profiledetails

I am able to run Join query and access the data and send to view.

But when I am manipulation the field 'dob' (date format) in profiledetails table. No Success, Please check the code below ,

webpagesConroller:

$users = DB::table('users')
        ->join('profiledetails', 'users.id', '=', 'profiledetails.user_id')  
        ->select('users.*', 'profiledetails.dob')
        ->get();
    $age = $users->dob->diffInYears(Carbon::now());         
    return view('webpages.index',compact('users'))->with($age);

View:

<li class="cate_head">Age : {{ $age}}</li>

Error:

Trying to get property of non-object

I have model Profiledetails added the mutators as below,

  public function getAge(){

       return $this->dob->diffInYears(Carbon::now());            

    }

    public function getDOB(){
        return $this->dob->format('d-m-Y');
    }

Can I not use this method on another controller for Ex- webpagesController, If yes How.

20 Feb
3 years ago

sanainfotech left a reply on Calculate Age From Date Stored In Database In Y-m-d

Thank s, @ohffs , That was easy and awesome with carbon.

How to change the format from datebase 'Y-m-d' to and 'm-d-Y' view?

sanainfotech started a new conversation Calculate Age From Date Stored In Database In Y-m-d

Hi User's add their DOB through the Form that store in database, I would like calculate age from stored date in the database which is in this format Y-m-d, My Question is : How to calculate ? Where to put the logic , In Controller or Model? How to pass the result of logic which is age in view.

18 Jan
3 years ago

sanainfotech left a reply on Calculate Age From Date Stored For All Profiles In MySql Column

Hi @martinbean, I have changed, as my column in database table is dob, So ,

@foreach ($users as $user)
{{ $user->dob->age }}
@endforeach 



class User extends Authenticatable
{
protected $casts = [
    'dob' => 'date',
];
}

sanainfotech left a reply on Calculate Age From Date Stored For All Profiles In MySql Column

@martinbean Thanks for quick answer, It seems to be perfect solution, But I am getting error in viewing the page as below,

ErrorException in  line 33:
Trying to get property of non-object (View: 

sanainfotech started a new conversation Calculate Date Stored For All Profiles In MySql Column

Hi, I have stored Date of birth for all profiles in my MySQL, Now on my index page, I would like to show all profile with their age.

  public function index(User $user){
    $users = $user->join('personaldetails', 'users.id', '=', 'personaldetails.user_id')-           
  >get();
    
    
    return view('index',compact('users'));
}

The above code joins 2 table which is 'users' and 'personaldeatails' , I am able to echo all feilds but What is the best way to echo age of all theses profiles

07 Jan
3 years ago

sanainfotech left a reply on $errors Variable Not Available

Finally, that's the right answers, using facade solved my code error. Thanks at lot @bestmomo .

Controller:

 public function store(creatquranRequest $request, quran $quran){
          $quran->create($request->all());       
          return redirect('quran');
           }
06 Jan
3 years ago

sanainfotech left a reply on $errors Variable Not Available

@bestmomo Thank for that , After changing as you mention above, I am getting an error telling

ErrorException in routes.php line 34:
Undefined variable: router

sanainfotech left a reply on $errors Variable Not Available

Hi @bestmomo Yes it's 5.2 version In my controller as follows

$router->resource('quran','quranController');

Route::group(['middleware' => ['web']], function () {
//
 });

Is the enough do I need something else to add

sanainfotech left a reply on $errors Variable Not Available

Hi , I am having exactly same problem as mention by @mydsrn. I have tried below code @if ($errors->any())

@endif The error is the same as below

Undefined variable: errors (View: 

I tried the following below code per your suggestion and it removed the Exception Error but does not display the errors.

@if (Session::get('errors'))
<ul>
    @foreach ($errors->all() as $error)
        <li>{ { $error } }</li>
    @endforeach
</ul>

@endif