behnampmdg3

behnampmdg3

Member Since 4 Years Ago

Experience Points 16,710
Experience
Level
Lessons Completed 89
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

24 Dec
4 weeks ago

behnampmdg3 left a reply on Basic Split Test Without DB Access

But guys I don't have a database.

Also visitors are from all around the world.

It's not on one computer.

23 Dec
4 weeks ago

behnampmdg3 started a new conversation Basic Split Test Without DB Access

Hi;

I want to send half of the traffic to Yahoo and have to Google.

1 - Is this way of redirecting correct? 2 - Anyways to make the distribution 100% accurate?

Thanks

29 Nov
1 month ago

behnampmdg3 started a new conversation Issue With CKeditor

Hi;

I usually use npm to add js packages.

This time I decided to add something manually.

The candidate is https://artisansweb.net/install-use-ckeditor-laravel/

Everything seems to be ok however, I get these errors:

https://ibb.co/Btf1x2r

Obviously can't load the CKeditor resources.

Here is the app.js file:

require('./bootstrap');
require('../../vendor/unisharp/laravel-ckeditor/ckeditor.js');


$(document).ready(function() {
  //Load CKeditor
  CKEDITOR.replace( 'body' );

  //Code highlighter
  $('pre code').each(function(i, block) {
    hljs.highlightBlock(block);
  });

  
});

window.Vue = require('vue');

import hljs from 'highlight.js';
import 'highlight.js/styles/github.css'

window.hljs = hljs;

And this is my directory structure

https://ibb.co/ydDkb4D

behnampmdg3 left a reply on Issue With CKeditor And Laravel

I had the id wrong. Thanks

behnampmdg3 started a new conversation Issue With CKeditor And Laravel

Hey guys I am using this https://artisansweb.net/install-use-ckeditor-laravel/

But I get the error below in the console.

What am I doing wrong?

app.js:6871 jQuery.Deferred exception: Cannot read property 'getEditor' of undefined TypeError: Cannot read property 'getEditor' of undefined
    at a (http://127.0.0.1:8000/js/app.js:70821:169397)
    at Object.CKEDITOR.replace (http://127.0.0.1:8000/js/app.js:70821:172033)
    at HTMLDocument.<anonymous> (http://127.0.0.1:8000/js/app.js:13902:12)
    at mightThrow (http://127.0.0.1:8000/js/app.js:6587:29)
    at process (http://127.0.0.1:8000/js/app.js:6655:12) undefined
jQuery.Deferred.exceptionHook @ app.js:6871
process @ app.js:6659
setTimeout (async)
(anonymous) @ app.js:6693
fire @ app.js:6321
fireWith @ app.js:6451
fire @ app.js:6459
fire @ app.js:6321
fireWith @ app.js:6451
ready @ app.js:6931
completed @ app.js:6941
app.js:70821 Uncaught TypeError: Cannot read property 'getEditor' of undefined
    at a (app.js:70821)
    at Object.CKEDITOR.replace (app.js:70821)
    at HTMLDocument.<anonymous> (app.js:13902)
    at mightThrow (app.js:6587)
    at process (app.js:6655)

Here is app.js

require('./bootstrap');
require('../../vendor/unisharp/laravel-ckeditor/ckeditor.js');


$(document).ready(function() {
  //Load CKeditor
  CKEDITOR.replace( 'summary-ckeditor' );

  //Code highlighter
  $('pre code').each(function(i, block) {
    hljs.highlightBlock(block);
  });

  
});

window.Vue = require('vue');

import hljs from 'highlight.js';
import 'highlight.js/styles/github.css'

window.hljs = hljs;


Here is my edit form

@extends('layouts.master')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
          <div class="clearfix">
            <a href="/posts" class="btn btn-info mb-1 float-right">Back to Posts</a>
          </div>  
            <!---->
            @include('errors.errors')
            <form action="/posts/{{$post->id}}" method="POST">
              @method('PATCH')
              @csrf
              <div class="form-group">
                <input type="text" class="form-control" id="title" name="title" placeholder="title" value="{{ old('title', $post->title) }}">
              </div>
              <div class="form-group">
                <textarea class="form-control" id="body" rows="4" name="body" id="summary-ckeditor" placeholder="Body">{{ old('title', $post->bodyEdit()) }}</textarea>
              </div>
              <button type="submit" class="btn btn-info">Submit</button>
            </form>    
            <!---->
        </div>
    </div>
</div>
@endsection
27 Nov
1 month ago

behnampmdg3 left a reply on How To Escape "part Of" User Data...

2 - How to escape html tags and keep these as exceptions:

<pre><code class=\"php\"> and </code></pre>

Thanks

behnampmdg3 started a new conversation How To Escape "part Of" User Data...

Hi;

I have 2 questions:

1 - How to make this code clean out of view so each time I show $post->body I do the replacement.

2 - Where do I move this code

<?php $body = str_replace("[CODE]", "<pre><code class=\"php\">", $post->body);?>
<?php $body = str_replace("[/CODE]", "</code></pre>", $body );?>
<p>{!! nl2br(e($body)) !!}</p>

2 - How to escape without removing these:

<pre><code class=\"php\"> and </code></pre>

Thanks

behnampmdg3 left a reply on Best Practice To Use Js With Laravel

@MUNAZZIL - That was a retarded move I made just there.

CSS is loading well, so is Javascript.

Still can't get highlight.js to work.

Ideas?

app.js

require('./bootstrap');
window.Vue = require('vue');

import hljs from 'highlight.js';
window.hljs = hljs;

$(document).ready(function() {
  $('pre code').each(function(i, block) {
    hljs.highlightBlock(block);
  });
});
26 Nov
1 month ago

behnampmdg3 left a reply on Best Practice To Use Js With Laravel

Hey;

I followed the instructions.

When I make updates to app.scss, I see The window pop up "LARAVEL MIX BUILD SUCCESSFUL".

However, I don't see the changes applying to the page.

Same with app.js, I see The window pop up "LARAVEL MIX BUILD SUCCESSFUL".

However, I don't see the changes applying to the page.

What am I doing wrong?

behnampmdg3 left a reply on Best Practice To Use Js With Laravel

@SIMPLYCOREY - All I want is to simply use highlight.js

behnampmdg3 left a reply on Best Practice To Use Js With Laravel

Not sure why this is so difficult to figure out.

There are devDependencies and dependencies. Not sure what's the difference.

I did npm install and it added so much inside node_modules.

packages.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "vue": "^2.5.17"
    },
    "dependencies": {
        "highlight.js": "^9.13.1"
    }
}

25 Nov
1 month ago

behnampmdg3 started a new conversation Best Practice To Use Js With Laravel

Hi;

I installed npm install highlight.js

It added node_modules to root and added highlight.js directory there.

I notice my packages.json file also added

"dependencies": {
        "highlight.js": "^9.13.1"
    }

What would be the correct way of including this js file to my pages?

Also if there is a Laracast series on this please link me.

Thank you

behnampmdg3 started a new conversation The Best Markup PHP Code Highlighter For Laravel

Hi;

What is the best markup PHP code highlighter for Laravel?

Basically for a forum that users can share posts with code.

Like Laracasts.

Thanks

behnampmdg3 started a new conversation Issue With Deleted Models And BelongsTo

Hi;

What is the best practice to not show comments that belong to a deleted post?

1 - Delete the comment as the post is deleted too? 2 - Change the comment model belongsTo relationship

<h3>Comments ( {{ $user->comments->count()}} )</h3>
  @forelse($user->comments as $comment)
    <a href = "/posts/{{ $comment->post_id }}">{{ $comment->post->title }}</a> {{ $comment->created_at->diffForHumans() }} <hr />
  @empty
  @endforelse
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    protected $fillable = ['body','post_id'];
    public function user()
        {
            return $this->belongsTo('App\User');
        }
    public function post()
        {
            return $this->belongsTo('App\Post');
        }   
}

behnampmdg3 left a reply on Is There A Better Way To Delete A Record?

@SNAPEY - Thanks, Snapey;

In this case

abort_unless(Auth::user()->isAdmin(), 403);

Let's say I am not after 'roles' here. But just a simple "is admin or not".

Would it be the good practice to make isAdmin() method in User model for example?

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];
    
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function posts()
        {
            return $this->hasMany('App\Post');
        }
    public function comments()
        {
            return $this->hasMany('App\Comment');
        }
    public function isAdmin()
        {
            return $this->is_admin;
        }        
}

CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_verified_at` timestamp NULL DEFAULT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `is_admin` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

behnampmdg3 left a reply on Blade Nl2br And A CSS Question

Hey Lunah;

Thanks, I like your function.

However, I rather not keep it the main model.

What would be the best practice? A better place to keep this code?

Is this where repository or service container comes handy?

Thanks

behnampmdg3 started a new conversation Css Question. Placing Buttons And Form On The Same Line.

Hi;

What is the proper way of placing Edit And Delete button on the same line? Please note delete is inside of a form (obviously).

<!-- Blog Post -->
              <div class="card mb-4">
                <div class="card-body">
                  <h2 class="card-title">{{ $post->title }}</h2>
                  <p class="card-text">{{ $post->body }}</p>
                </div>
                <div class="card-footer text-muted">
                  {{ $post->created_at->diffForHumans() }}
                  <a href="/users/{{ $post->user->id }}">{{ $post->user->name }}</a>

                  @if(Auth::id()===$post->user_id)
                  <a href="/posts/{{ $post->id }}/edit" class="btn btn-secondary btn-sm">Edit &rarr;</a> 
                  <form method = "POST" action="/posts/{{ $post->id }}">
                    @csrf
                    @method('DELETE')
                    <input type="submit" class="btn btn-danger btn-sml" value="Delete">
                  </form>  
                  @endif
                </div>
              </div>
            <!---->

behnampmdg3 left a reply on Is There A Better Way To Delete A Record?

Sweet as.... now, how do you check if this post belongs to this logged user?

What's the best practice?

Thanks

24 Nov
1 month ago

behnampmdg3 started a new conversation Is There A Better Way To Delete A Record?

Is there a better way to delete?

public function destroy(Post $post)
    {
        $flight = Post::find($post['id']);
        $flight->delete();
        return redirect('/posts');
    }
@if(Auth::id()===$post->user_id)
                  <a href="/posts/{{ $post->id }}/edit" class="btn btn-secondary">Edit &rarr;</a> 
                  <form method = "POST" action="/posts/{{ $post->id }}">
                    @csrf
                    @method('DELETE')
                    <input type="submit" class="btn btn-danger" value="Delete">
                  </form>  
@endif

behnampmdg3 started a new conversation ErrorException (E_WARNING) Use Of Undefined Constant Request - Assumed 'request' (this Will Throw An Error In A Future Version Of PHP)

Hello;

How come I get this? In Jeff's video, it works

<?php

namespace App\Http\Controllers;

use App\Post;
use Illuminate\Http\Request;
use App\Http\Requests\StoreBlogPost;

class PostController extends Controller
{
    
    public function edit(Post $post)
    {
        dd(request);

    }

    
}

behnampmdg3 left a reply on Delete Method Not Allowed

@snapey

How do you validate and make sure this post belongs ot this logged user.... so I can't delete your posts?

behnampmdg3 left a reply on Where Would You Move This Code?

@snapey

Thanks.

Is there a better way to access id in form request?

public function persist()
    {
        $id=request()->route()->parameter('post')->id;
        return $this->user()->posts()->updateOrCreate(
            ['id' => $id],[
            'title' => $this->title,
            'body' => $this->body
        ]);
    }

behnampmdg3 left a reply on Where Would You Move This Code?

@snapey

I am changed your code to UpdateOrCreate, should technically work but I get

"The title has already been taken."

public function persist()
    {
        return $this->user()->posts()->updateOrCreate([
            'title' => $this->title,
            'body' => $this->body,
            'youtube_video_id' => $this->youtube_video_id,
            'category_id' => $this->category_id,
        ]);
    }

What is the best practise?

Thank you

23 Nov
1 month ago

behnampmdg3 started a new conversation Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Class 'Illuminate\App\Providers\ComposerServiceProvider' Not Found

Hey fellows;

What am I doing wrong?

Thanks

$ composer dump-autoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In ProviderRepository.php line 208:
                                                                      
  Class 'Illuminate\App\Providers\ComposerServiceProvider' not found  
                                                                      

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
<?php

//Stored at app/Http/ViewComposers

namespace App\Providers;

use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function boot()
    {
        // Using Closure based composers...
        $posts = array(1,2);
        View::composer('*', function ($view) {
                $view->with('posts', $posts);
       });
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Application Name
    |--------------------------------------------------------------------------
    |
    | This value is the name of your application. This value is used when the
    | framework needs to place the application's name in a notification or
    | any other location as required by the application or its packages.
    |
    */

    'name' => env('APP_NAME', 'Laravel'),

    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services the application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),

    /*
    |--------------------------------------------------------------------------
    | Application Debug Mode
    |--------------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */

    'debug' => env('APP_DEBUG', false),

    /*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */

    'url' => env('APP_URL', 'http://localhost'),

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */

    'timezone' => 'UTC',

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */

    'fallback_locale' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Faker Locale
    |--------------------------------------------------------------------------
    |
    | This locale will be used by the Faker PHP library when generating fake
    | data for your database seeds. For example, this will be used to get
    | localized telephone numbers, street address information and more.
    |
    */

    'faker_locale' => 'en_US',

    /*
    |--------------------------------------------------------------------------
    | Encryption Key
    |--------------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */

    'key' => env('APP_KEY'),

    'cipher' => 'AES-256-CBC',

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,
        Illuminate\App\Providers\ComposerServiceProvider::class,

        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

    ],

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,

    ],

];

11 Nov
2 months ago

behnampmdg3 started a new conversation Laravel Tags Vs Wordpress Tags (SEO)

Hello;

I have a question about tags I'd appreciate some advice.

I am about to build a blog and post a couple hundred articles and I am a bit unsure about "tags".

I can't find watched Jeff's video on tags (I think it was in 5.4 from scratch) from what I recall, he made a tags table and simply assigned tags to posts in a manyToMany relationship (i might be wrong).

I can build that no issues. What I am not sure about is the purpose of tags and how they speak about it in regards to Wordpress.

For example:

/// https://trafficgenerationcafe.com/blog-tags-seo/

As I previously mentioned, when you use tags, you instantly create new pages for your blog that are fully indexable, searchable, and rankable. In other words, you create additional content that can bring search engine visitors.

" you instantly create new pages for your blog that are fully indexable, searchable, and rankable"?!?!?!?

What is that about? Are tags used for SEO? What is the purpose of adding tags to posts the way Jeff does?

Thanks

09 Nov
2 months ago

behnampmdg3 left a reply on Where Would You Move This Code?

@snapey

How is it possible that 'PostRequest ' can access $this->user()?

07 Nov
2 months ago

behnampmdg3 started a new conversation PLEASE BRING BACK THE OLDER LARACAST DESIGN

Jeff, I love you for everything you've done so far but this site update...

The other one was so much more classy and easier to follow.

06 Nov
2 months ago

behnampmdg3 started a new conversation Issue Installing Cashier

Anyone knows what's going on here?

composer require laravel/cashier
Using version ^8.0 for laravel/cashier
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/cashier v8.0.0 requires stripe/stripe-php ~5.0 -> satisfiable by stripe/stripe-php[v5.0.0, v5.1.0, v5.1.1, v5.1.2, v5.1.3, v5.2.0, v5.2.1, v5.2.2, v5.2.3, v5.3.0, v5.4.0, v5.5.0, v5.5.1, v5.6.0, v5.7.0, v5.8.0, v5.9.0, v5.9.1, v5.9.2] but these conflict with your requirements or minimum-stability.
    - laravel/cashier 8.0.x-dev requires stripe/stripe-php ~5.0 -> satisfiable by stripe/stripe-php[v5.0.0, v5.1.0, v5.1.1, v5.1.2, v5.1.3, v5.2.0, v5.2.1, v5.2.2, v5.2.3, v5.3.0, v5.4.0, v5.5.0, v5.5.1, v5.6.0, v5.7.0, v5.8.0, v5.9.0, v5.9.1, v5.9.2] but these conflict with your requirements or minimum-stability.
    - Installation request for laravel/cashier ^8.0 -> satisfiable by laravel/cashier[8.0.x-dev, v8.0.0].


Installation failed, reverting ./composer.json to its original content.

behnampmdg3 started a new conversation How Would You Clean This Up?

It's basic stuff. Please show me how you clean this up.

Thanks

 <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Stripe\{Stripe, Charge, Customer};

class PaymentController extends Controller
{
    public function index()
        {
            return view('payment');
        }
    public function pay(Request $request)
        {
        
      //If not stripe customer, create customer in stripe and update stripe_customer_id field in the database
      if(!auth()->user()->stripe_customer_id)
        {
          \Stripe\Stripe::setApiKey(config('services.stripe.secret'));
            $customer = Customer::create(
               ['email' => $request['stripeEmail']
               , 'source'=>$request['stripeToken']]
            );
            $stripe_customer_id = $customer->id;
            $user = auth()->user();
            $user->stripe_customer_id = $stripe_customer_id;
            $user->save();
        }  
        else 
        {
            $stripe_customer_id = auth()->user()->stripe_customer_id;
        }
        Charge::create([
            'amount'=>2500,
            'customer' => $stripe_customer_id,
            'currency' => 'usd'
        ]);
        
            return redirect('users/'.\Auth::id());
        }   
}

behnampmdg3 left a reply on Where Would You Move This Code?

Hi, @SapporoGuy

Thanks, it makes sense. I get the same feeling

This guy @Snapey seems to be one of the best in the forum.

I am going with his approach even though it doesn't make 100% sense to do CRUD in FOrRequest thingy.

behnampmdg3 started a new conversation How Do Tags Work With Search Engine?

Hey

Not much Laravel related but tags Jeff makes per post, how do they work with search engines?

04 Nov
2 months ago

behnampmdg3 started a new conversation What Is A Good Solution For One Time Payments?

Hi;

Cashier seems like a great solution for recurring billing.

What is a good solution for one time payments?

I see Jeff has archived the Stripe series.

Thanks

behnampmdg3 started a new conversation How Come Jeff Archived Stripe Series?

Hi;

How come Jeff archived Stripe series? The first video seems to work pretty smoothly.

Is there specific things that are dated now?

https://laracasts.com/series/billing-with-stripe

Thanks

31 Oct
2 months ago

behnampmdg3 left a reply on Are There Videos On Laracast To Set User Roles?

These videos seem outdated.

There is no such thing as this anymore.

php artisan  generate

behnampmdg3 left a reply on Where Would You Move This Code?

@Snapey

Hey man. I read your method and I get it.

I know you're an expert forum member. No doubt you have a point.

However, I don't understand why you're doing the "database business" in FormRequest.

I was under the impression that FormRequest is for form validation and we use model, controller or repository for database-business.

What's the deal man?

Thanks

behnampmdg3 started a new conversation Are There Videos On Laracast To Set User Roles?

If so, link, please.

Otherwise, where is a good resource (for 5.7)?

Thanks

behnampmdg3 left a reply on Where Would You Move This Code?

@cronix how do you add user_id?

$post->user_id = \Auth::user()->id;

behnampmdg3 left a reply on Where Would You Move This Code?

Cronix's idea seems like the cleanest one.

@Spporoguy why would you add a repository when you could just go like Cronix mentioned?

I don't understand why it's a good practice to add repositories.

Thanks

29 Oct
2 months ago

behnampmdg3 left a reply on Where Would You Move This Code?

Hi;

I know how to do it. Several ways. I am asking different user's opinions.

Jeff Teaches several ways but he doesn't make it clear which one is prefered and why.

That's why I wanna hear other's opinions.

Tanx

behnampmdg3 started a new conversation Where Would You Move This Code?

Hello;

Where would be a good place to keep this code?

A) PostController B) Post Model C) A Repository D) Somewhere else

If your answer is not A, please explain why and how.

Thank you.

public function store(Request $request)
    {
        $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
        ]);

        $post = new Post;
        $post->title = $request->title;
        $post->body = $request->body;
        $post->user_id = \Auth::user()->id;
        $post->save();
        
        return redirect('/posts');
    }

behnampmdg3 left a reply on BelongsTo Not Working!

Hi. This works

{{ $comment->post['title'] }}

Can someone explain why?

behnampmdg3 started a new conversation BelongsTo Not Working!

Very strange, I get this. What am I doing wrong?

Not getting "$comment->post->title".

Trying to get property 'title' of non-object (View: /Users/bj/codes/blog/resources/views/users/show.blade.php)
<ol>
    @forelse($user->comments as $comment)
    dd($comment);
        <li>{{ $comment->body }} <br />
            On Post {{ $comment->post->title }} On {{ $comment->created_at->diffForHumans() }}</li>
    @empty
        <p>This user has no comments</p>
    @endforelse
</ol>
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    protected $fillable = ['body','user_id'];

    public function user()
        {
            return $this->belongsTo(User::class);
        }
    public function post()
        {
            return $this->belongsTo(Post::class);
        }   
}
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    public function comments()
        {
            return $this->hasMany(Comment::class);
        }

   public function user()
        {
            return $this->belongsTo(User::class);
        }       

public function scopeFilter($query, $request)
    {
        if($request['month'])
            {
                $query->whereMonth('created_at', date('m',strtotime($request['month'])));
            }   
        if($request['year'])
            {
                $query->whereYear('created_at', $request['year']);
            }       
    }
}
<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    protected $fillable = ['name','email','password'];

    public function posts()
        {
            return $this->hasMany('App\Post');
        }
     public function comments()
        {
            return $this->hasMany('App\Comment');
        }    
}
24 Oct
2 months ago

behnampmdg3 left a reply on Where Is A Beginners Tutorial For Scopes?

Hey @D9705996

No, I am a bit confused because he says

we briefly spoke about scopes in the previous episode But it's not in the serious so far.

That's why I asked, I haven't missed any of these so far but not sure what he's referring to.

There has to be a video about scopes before this.

23 Oct
2 months ago

behnampmdg3 started a new conversation Where Is A Beginners Tutorial For Scopes?

Hi;

In this one, Jeff starts talking about scopes with no intro it's a bit confusing.

https://laracasts.com/series/laravel-from-scratch-2017/episodes/20?autoplay=true

Can someone please link me to beginners tutorial for Scopes?

Thanks