a4ashraf

a4ashraf

Member Since 3 Months Ago

Experience Points
82,110
Total
Experience

2,890 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
690
Lessons
Completed
Best Reply Awards
14
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 17
82,110 XP
Apr
07
19 hours ago
Activity icon

Replied to Resource API Data

@brunitosessa

here how you will add the calculate distance function in your controller

class BarController extends Controller
{
    public function index(Request $request) {
        $lat = $request->input('lat',0);
        $lng = $request->input('lng',0);

        $distance = $this->calculateDistance($lat, $lng);

        $request->request->add(['distance' => $distance]);

        return [
        	'estado' => 1,
        	'bares' => BarResource::collection(Bar::All()),
        ];   
    }

    protected function calculateDistance($lat, $lng) 
	{ 
		//your calculation code 
			
		return $distance; 
	} 
Activity icon

Replied to It Returns 404 For The Public Directory.

Hi @analien

where are your style file located

try this one

<link rel="stylesheet" href="{{ asset('css/my-style.css') }}">
Apr
05
2 days ago
Activity icon

Replied to Resource API Data

@brunitosessa

you should create it in you controller or if you are using any pattern you should it in that particular pattern file

if you share you controller or pattern file I can help you

Apr
04
3 days ago
Activity icon

Awarded Best Reply on ERROR: Call To A Member Function FullName() On Null

Hello @noblemfd

you need to create you accessor correct format in your model class

like this

public function getFullNameAttribute()
{
    return $this->first_name . ' ' . $this->other_name . ' ' . $this->last_name;
}

and call it in your view class

{{ $employee->linemanager->fullName() ?? 'None' }}
Activity icon

Replied to How To Upload Json File And Extract In Laravel 7

@nafeeur10

check your form HTML in the Blade file. it should be this

enctype="multipart/form-data"

and 2nd point may be an issue in this path public_path('uploads'),

run this command following

php artisan storage:link

Activity icon

Replied to Resource API Data

@brunitosessa

here is the solution to calculate the distance between two points

<?php 
		
	function twopoints_on_earth($latitudeFrom, $longitudeFrom, 
									$latitudeTo, $longitudeTo) 
	{ 
		$long1 = deg2rad($longitudeFrom); 
		$long2 = deg2rad($longitudeTo); 
		$lat1 = deg2rad($latitudeFrom); 
		$lat2 = deg2rad($latitudeTo); 
			
		//Haversine Formula 
		$dlong = $long2 - $long1; 
		$dlati = $lat2 - $lat1; 
			
		$val = pow(sin($dlati/2),2)+cos($lat1)*cos($lat2)*pow(sin($dlong/2),2); 
			
		$res = 2 * asin(sqrt($val)); 
			
		$radius = 3958.756; 
			
		return ($res*$radius); 
	} 

	// latitude and longitude of Two Points 
	$latitudeFrom = 19.017656 ; 
	$longitudeFrom = 72.856178; 
	$latitudeTo = 40.7127; 
	$longitudeTo = -74.0059; 
		
	// Distance between Mumbai and New York 
	print_r(twopoints_on_earth( $latitudeFrom, $longitudeFrom, 
					$latitudeTo, $longitudeTo).' '.'miles'); 

// This code is contributed by akash1295 
// https://auth.geeksforgeeks.org/user/akash1295/articles 
?> 

https://www.geeksforgeeks.org/program-distance-two-points-earth/

Activity icon

Replied to ERROR: Call To A Member Function FullName() On Null

Hello @noblemfd

you need to create you accessor correct format in your model class

like this

public function getFullNameAttribute()
{
    return $this->first_name . ' ' . $this->other_name . ' ' . $this->last_name;
}

and call it in your view class

{{ $employee->linemanager->fullName() ?? 'None' }}
Mar
24
2 weeks ago
Activity icon

Started a new Conversation I Got DNS_PROBE_FINISHED_NXDOMAIN Error When I Access Domain Through Laravel Valet

Hello

I'm facing DNS_PROBE_FINISHED_NXDOMAIN error when I access the domain blog.test

I do the following steps

sudo brew services stop nginx

sudo brew services stop [email protected]

sudo brew services stop dnsmasq

valet install

and its start my PHP, dnsmasq , and nginx but still facing the error DNS_PROBE_FINISHED_NXDOMAIN

Mar
20
2 weeks ago
Activity icon

Replied to How To Refactor This Code?

@armani

Please share output of $request->all()

Mar
19
2 weeks ago
Activity icon

Awarded Best Reply on Error On DB Where!

@randy_johnson

try this, you miss actually get method in your statement

$data = DB::table($this->tablex)->where('user_id', Auth::user()->id)->get();

Mar
04
1 month ago
Activity icon

Replied to RefreshDatabase Don't Clear Seeder

@mrjmpl3

if you want to truncate all the tables you need to run the "fresh" command with seeder


php artisan migrate:fresh --seed

it will drop all tables and then create those tables again with your db seeder

Activity icon

Replied to Can,t Create New Video

Hi @asaadon

correct your Migration file it should be nullable()

public function up() { 
Schema::create('vedieos', function (Blueprint $table) { 
	$table->bigIncrements('id'); 
	$table->string('NAME'); 
	$table->string('META_KEYWORDS')->nullable(); 
	$table->string('DESC')->nullable(); 
	$table->text('META_DESC')->nullable(); 
	$table->string('YOUTUBE')->nullable(); 
	$table->boolean('PUBLISHED')->default(1); 
	$table->integer('USER_ID')->nullable(); 
	$table->integer('CAT_ID')->nullable(); 
	$table->string('IMAGE')->nullable(); 
	$table->timestamps(); 

}); }
Mar
03
1 month ago
Activity icon

Replied to Subdomain To Maindomain Routing

Hello @talentedaamer

try this


Route::domain('{account}.myapp.com')->group(function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});

see the route documentation

https://laravel.com/docs/5.7/routing#route-group-sub-domain-routing

Mar
02
1 month ago
Activity icon

Replied to Checkbox Inserts

Hi @artisticre

Try this


        $teamapp->clergy = collect($request->input('clergy'))->toJson();

    // Or

    $teamapp->clergy = collect($request->clergy)->toJson();

Mar
01
1 month ago
Activity icon

Replied to Validate Dynamic Fields With FromRequest In Laravel

@snapey @rjruiz

yes we should use this handy solution


$rules = [             
        'denomination' => 'required',
        'code' => 'required',           
        'part_piece' => 'required',
        'number_gag' => 'required',          
        'number_program' => 'required',         
        'time' => 'required',    
    'addmore.*.position' => 'required';
    'addmore.*.code_tool' => 'required';
    'addmore.*.code_insert' => 'required';
    'addmore.*.quality' => 'required';
    ];

Activity icon

Awarded Best Reply on Validate Dynamic Fields With FromRequest In Laravel

@rjruiz

Try this


$rules = [             
        'denomination' => 'required',
        'code' => 'required',           
        'part_piece' => 'required',
        'number_gag' => 'required',          
        'number_program' => 'required',         
        'time' => 'required',         
    ];

    if($this->request->get('addmore')){
        foreach($this->request->get('addmore') as $key => $val)
        {
            $rules['addmore.'.$key.'.position'] = 'required';
            $rules['addmore.'.$key.'.code_tool'] = 'required';
            $rules['addmore.'.$key.'.code_insert'] = 'required';
            $rules['addmore.'.$key.'.quality'] = 'required';
        }
    }

    return $rules;

Activity icon

Replied to Validate Dynamic Fields With FromRequest In Laravel

@rjruiz

Try this


$rules = [             
        'denomination' => 'required',
        'code' => 'required',           
        'part_piece' => 'required',
        'number_gag' => 'required',          
        'number_program' => 'required',         
        'time' => 'required',         
    ];

    if($this->request->get('addmore')){
        foreach($this->request->get('addmore') as $key => $val)
        {
            $rules['addmore.'.$key.'.position'] = 'required';
            $rules['addmore.'.$key.'.code_tool'] = 'required';
            $rules['addmore.'.$key.'.code_insert'] = 'required';
            $rules['addmore.'.$key.'.quality'] = 'required';
        }
    }

    return $rules;

Activity icon

Replied to Save A File With The Real Extension Of A File Not Tmp Extension

@jorge_dev96

is this solved now or you still any issue?

Activity icon

Awarded Best Reply on Save A File With The Real Extension Of A File Not Tmp Extension

@jorge_dev96

Can you share your Blade file, because your method is correct getClientOriginalExtension

but maybe issue with your input array

Activity icon

Replied to Save A File With The Real Extension Of A File Not Tmp Extension

@jorge_dev96

Can you share your Blade file, because your method is correct getClientOriginalExtension

but maybe issue with your input array

Feb
27
1 month ago
Activity icon

Replied to How To Access Eager Loaded Records From Single Model

Hi @naykel

it seems to, you have no data in your $menu->links table you must be used like following in your model file to avoid error

return $this->hasOne('App\Your-Model-Class')->withDefault();

//or 

return $this->hasMany('App\Your-Model-Class')->withDefault();

Feb
22
1 month ago
Activity icon

Replied to SQLSTATE[HY000] - No Default Value, I Dont Want A Default

Hi @naekobest

check your migration file or Database, I think this is "Enum" field and Enum field has a default value

if yes then you need to set the default value

Feb
20
1 month ago
Activity icon

Replied to How Can I Get The Results Of The Upcoming Month's Birthdays In Laravel

Hi @cyberace

Try this

select(DB::raw('FLOOR(DATEDIFF(birth_date,Carbon::today())/365) as Diff'))

Feb
19
1 month ago
Activity icon

Awarded Best Reply on Property [id] Does Not Exist On This Collection Instance.

@oxbir

you are getting more than one rows in. $gallery->categories

use nested foreach in your blade file


@foreach($gallery->categories as $category)
    
your html 

@endforeach
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

@oxbir

you are getting more than one rows in. $gallery->categories

use nested foreach in your blade file


@foreach($gallery->categories as $category)
    
your html 

@endforeach
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

@oxbir

try this

$galleries = Gallery::with('categories')->whereNotNull('image')->latest()->paginate(25);
    
$categories = Category::where('parent_id', 42)->with('galleries')->get();
    
return view('Home.galleries', compact('galleries', 'categories'));
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

@oxbir

Try now


$galleries = Gallery::with('categories')->whereNotNull('image')->latest()->paginate(25);
    
$categories = Category::where('parent_id', 42)->with('galleries')->get();
    
return view('Home.galleries', compact('galleries', 'categories'));
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

@oxbir

Please create Model function for category in your Gallery Model

Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

@oxbir

Try this

$galleries = Gallery::with('category')->whereNotNull('image')->latest()->paginate(25);
    
$categories = Category::where('parent_id', 42)->with('galleries')->get();
    
return view('Home.galleries', compact('galleries', 'categories'));
Activity icon

Replied to Resolving Object Of Class StdClass Could Not Be Converted To String

Hi @noblemfd

Try this


$linemanageremployee = DB::table('hr_employees')->where('line_manager_id', 
$linemanager->line_manager_id)->first();

$goals = AppraisalGoal::where('employee_id', $linemanageremployee->id)->where('appraisal_identity_id', $identities->id)->get();


return view('appraisal.appraisal_goals.manager_employee_list')->with('goals', $goals);
Activity icon

Replied to Resolving Object Of Class StdClass Could Not Be Converted To String

@noblemfd

try this one


$linemanageremployee = DB::table('hr_employees')->where('line_manager_id', 
$linemanager->line_manager_id)->first();

    $linemanageremployee->your_id_field;
Activity icon

Replied to Resolving Object Of Class StdClass Could Not Be Converted To String

Hi @noblemfd

change with following code


$linemanageremployee = DB::table('hr_employees')->where('line_manager_id', $linemanager->line_manager_id)->get('id');  

Activity icon

Replied to Getting $ Not Defined Error

Hi @krishma

Try this, your msg alert should be shown first


 <script src="https://code.jquery.com/jquery-3.4.1.js"></script>

<script type='text/javascript'>

function remove(id) {    

    if (confirm('Are you sure want to Delete this data?')) {
      
        jQuery.ajax({
                url: "{{ url('AssetCategoryController/delete') }}",
                type: 'get',
                data: { id: id},
            dataType: 'json',
                success: function (data) {
                        jQuery('#' + id).remove();
                        return false;
                }
        });
    }
}
</script>

Activity icon

Replied to Raw Input Into DB

Hi @lavina

Try this one, its work for you, replace your fields with Data object

App\Product::createMany([
        [
            'name' => $data->your_name,
            'description' => $data->description,
            'created_at' => $data->created_at,
            'updated_at' => $data->updated_at,
        ],
        [
            'name' => $data->your_name,
            'description' => $data->description,
            'created_at' => $data->created_at,
            'updated_at' => $data->updated_at,
        ]
    ]);

Activity icon

Replied to Getting $ Not Defined Error

Hi @krishma

you need to include the Jquery file above this code and try this

 <script src="https://code.jquery.com/jquery-3.4.1.js"></script>

<script type='text/javascript'>

function remove(id){    
  jQuery.ajax({
    url: "{{ url('AssetCategoryController/delete') }}",
    type: 'get',
    data: { id: id},
    dataType: 'json',
    success: function (data) {
    var msg = confirm('Are you sure want to Delete this data?');
            if (msg == true) {
                jQuery('#' + id).remove();
                return false;
            }
        },
  });
}
</script>
Feb
18
1 month ago
Activity icon

Awarded Best Reply on Laravel Map Function For Nested Arrays

Hi @deepu07

Here is the solution but make sure your model has to relationship functions


    $output = [ "status" => "success"];

    $books = App\Book::with(['publishers', 'book_price'])->get();

    foreach ($books as $book) {
        
        $bookData = [
                    "book_id" => $book->id,
                    "book_type" => $book->book_type
                ];

        foreach ($book->publishers as $publisher) {

            $bookData['publisher'][] = [
                'id' => $publisher->id,
                'name' => $publisher->name,
                'location' => $publisher->location,
                'created_at' => $publisher->created_at,
            ];              

        }

        $output['data'][] = $bookData;
        
    }

    return response()->json($output);

Activity icon

Replied to Error On DB Where!

Hi @randy_johnson

Does this solve?

Activity icon

Replied to Laravel Map Function For Nested Arrays

Hi @deepu07

Here is the solution but make sure your model has to relationship functions


    $output = [ "status" => "success"];

    $books = App\Book::with(['publishers', 'book_price'])->get();

    foreach ($books as $book) {
        
        $bookData = [
                    "book_id" => $book->id,
                    "book_type" => $book->book_type
                ];

        foreach ($book->publishers as $publisher) {

            $bookData['publisher'][] = [
                'id' => $publisher->id,
                'name' => $publisher->name,
                'location' => $publisher->location,
                'created_at' => $publisher->created_at,
            ];              

        }

        $output['data'][] = $bookData;
        
    }

    return response()->json($output);

Activity icon

Replied to Update Dynamic Table

@rjruiz

can you share with me your project here is my skype a4ashraf24

Activity icon

Replied to Update Dynamic Table

@rjruiz

here is issue


 $piece  = Piece::with(['tools.insert'], 'gag', 'piece')->findOrFail($id); 


// replace with 

 $piece  = Piece::with('tools', 'insert', 'gag', 'piece')->findOrFail($id);
Activity icon

Replied to Json_encode Not Work In Custom Output

@larasell

Try this

$zoneNameByCountry = DB::table('zone')->where('country_id', '101')->first();
echo json_encode(['output'=>[$zoneNameByCountry]]);
Activity icon

Replied to Update Dynamic Table

@rjruiz

there is issue in your $request->all() , please send me dd($request->all()) output

Feb
17
1 month ago
Activity icon

Replied to Update Dynamic Table

@rjruiz

try this

$gag = Gag::where('gag_id', $piece ->id)->update($request->all());
$program = Program::where('program_id', $piece->program_id)->update($request->all());
Activity icon

Replied to Update Dynamic Table

@rjruiz

try this and please make sure you have $your-gag_id and $your-programe_id

$gag = Gag::where('gag_id', $your-gag_id)->update($request->all());
$program = Program::where('program_id', $your-programe_id)->update($request->all());               
Activity icon

Replied to Update Dynamic Table

@rjruiz

where you use this mb_strpos in your script?