mehany

PHP & JAVA developer at Arizona

Experience

61,260

39 Best Reply Awards

  • Member Since 3 Years Ago
  • 330 Lessons Completed
  • 2 Favorites

14th November, 2017

mehany left a reply on Homestead Hangs At SSH Auth Method: Private Key • 8 months ago

@laminbarrow brilliant

15th January, 2017

mehany left a reply on To "Repository Pattern" Or Not? • 1 year ago

The true answer for your question is "It depends" :) because applications are architected differently. For example you will find this pattern in Hexagonal Architecture.

My own two cents about repos:

Repository Pattern could be used to decouple specific functionality. A Repository that interacts with third party APIs should implement an interface.

I would say, I am on the side of avoiding repositories mostly because I can do so much with Eloquent and queryScopes. But I use repositories when I have a Modal that part of it interacts with third part APIs, something like special management reporting, user tracking, inventory etc... depending on the use case, sometimes I just put the logic in a class and not even repository.

Ex. here is a good use case for repository pattern which is specific to Datatables JS.

10th January, 2017

mehany left a reply on Show Html In Blade Email • 1 year ago

An html email should be something like this https://jsfiddle.net/q9ceu4jL/

9th January, 2017

mehany left a reply on MassAssignmentException And $guarded Is Set To [] • 1 year ago

Oh never mind... Just figured it out :)

mehany started a new conversation MassAssignmentException And $guarded Is Set To [] • 1 year ago

I have a model with two attributes name and description . I get MassAssignmentException while I have $guarded is set to [] am I missing something?

here is my model

class MyModal extends Model
{

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

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];

}

In my controller I do

    public function store(Request $request)
    {
        //
        $item = MyModal::create($request->input());

        return Response::json($item);
    }

Laravel Framework version 5.3.29

1st December, 2016

mehany left a reply on Preload A Laravel Page With JS • 1 year ago

This is often done with Js and Css. I used this js code before and I liked it, give it a try.

I used it like so , i added right after the <body> tag:

<script type="text/javascript">
      window.loading_screen = window.pleaseWait({
        logo: "/images/logo.svg",
        backgroundColor: '#ffffff',
        loadingHtml: 'Add html here'
      });
    </script>

Then after page loads all content

window.loading_screen.finish();

mehany left a reply on Composer Update Not Install Latest Version • 1 year ago

@MGMK are you using dompdf also in your composer.json? if so which version?

29th November, 2016

mehany left a reply on Laravel On VPS • 1 year ago

@LUKAISAILOVIC you seem to have your apache server configuration or apache php module not set properly ( this is for sure because you see files ) if you show some configurations, i may be able to help

mehany left a reply on How To Get All The Images Including The Ones In The Background(css) Of A Site Using Php? • 1 year ago

@kobear agree. Doing this with PHP will end up running in several limitations, I would do this with nodeJS and selenium instead. With selenium, you can automatically open a browser, inject scripts to read images, links and possibly grap the link of css files, download them locally then parse them as needed with any language.

9th June, 2016

mehany left a reply on Import Script From Composer Vendor In Main.js • 2 years ago

I see. The only thing I can think of is a syslink

mehany left a reply on Import Script From Composer Vendor In Main.js • 2 years ago

I use gulp like this: from where the gulpfile.js ./.. I go back one directory, ./ {pwd}, ./js {pwd}/js

So it goes by current directory. / refers to current directory where gulpfile.js is, same as require('./vendeor_file.js') will expect a file in current directory and require('underscore') for example will look for underscore in the node_modules dir. Have you tried to use './packages/vendor/package/src/js/file.js'?

You wil probably be interested in this blog post

4th June, 2016

mehany left a reply on LogicException In RouteCompiler • 2 years ago

string | 25 len maximum

mehany left a reply on LogicException In RouteCompiler • 2 years ago

When i try the code you provided, the router dispatches the action the ::show() method.

mehany left a reply on LogicException In RouteCompiler • 2 years ago

Ok thank you! but after that I looked into this, the problem is really making an option available to hook in the same resource name additional methods/actions when needed! Why? because I think that is an elegant syntax! something as the one you suggested Regular Expression Constraints would work as well.

I understand a crud resource is just intended for crud operations but I want to use the same resource name in the url for the index method. Hope this gives you better understanding @SaeedPrez of what I was after. Don't you people think this would be a cool feature?

mehany left a reply on LogicException In RouteCompiler • 2 years ago

Well i need crud so that is why I am using resource . Any ways, it looks like it is what it is, I just wish if i can pass to resource more actions. Not sure if this is possible. here is how I solved it earlier

Route::get('documents/list/{product?}', '[email protected]');
Route::resource('documents', 'ManageDocumentsController');

If you ever use Datatables.js along with complex data, you will run into this.

mehany left a reply on LogicException In RouteCompiler • 2 years ago

It looks like that does not work with resource.

mehany left a reply on LogicException In RouteCompiler • 2 years ago

ok @SaeedPrez, I wish to simply type resource and then it will work with a search parameter! but the router matches {type?} to {id?} so I would like to provide another parameter to list a sub type . To get a better idea here is the controller

public function index(Request $request, $product = null)
            $allPdfs = ($product != null) ?
            PdfDocument::where('pdf_type', '=', $product):
            PdfDocument::select('*');

        $pdfs =   Datatables::of($allPdfs)->make(true);


        if($request->wantsJson())
        {
            return $pdfs;
        }

        return view('admin.documents.index',
            ['page_title' => (($product != null) ?
                    $product : "" ). ' PDF documents List',
             'type'       => $product
            ]);

mehany left a reply on LogicException In RouteCompiler • 2 years ago

I think the reason is Route::resource('orders/{type?}' is the same as Route::resource('orders/{id?}' but I am not sure why one would work and the second don't!

mehany started a new conversation LogicException In RouteCompiler • 2 years ago

I have an app that has an admin panel. In the admin area Routes I have

    Route::resource('documents/{product?}', 'ManageDocumentsController'); 
    Route::resource('orders/{type?}', 'ManageOrdersController');

So I run this url in my browser ( example.com/admin/orders/download ), I get

Route pattern "/admin/documents/{product}/{{product}}" cannot reference variable name "product" more than once.

I run this url in my browser ( example.com/admin/documents/topo ) it renders the list.

If I switch the order or the route's declaration, it will do the same error. The one that comes after is the one that does not render :(

      Route::resource('orders/{type?}', 'ManageOrdersController');
      Route::resource('documents/{product?}', 'ManageDocumentsController'); 

     Route pattern "/admin/orders/{type}/{{type}}" cannot reference variable name "type" more than once.

28th April, 2016

mehany left a reply on Can't Connect To Forge MySQL Database From Local Deployment • 2 years ago

I assume you have a bash console! The below command will proxy port 3306 ( mysql port ) to your local computer. Then you will be able to use port 33065 and localhost to connect, of course remote DB credentials will be required. You can learn more about this on here.

ssh -L 33065:127.0.0.1:3306 server-ip -l server-user -p ssh-port -N

26th April, 2016

mehany left a reply on Stub And Publish A Custom Config File • 2 years ago

ok, thought there might be a prettier way.

mehany left a reply on Stub And Publish A Custom Config File • 2 years ago

yes

mehany started a new conversation Stub And Publish A Custom Config File • 2 years ago

What is a simple way to generate a stub with custom variables?

25th April, 2016

mehany left a reply on TokenMismatchException In VerifyCsrfToken.php • 2 years ago

@Snappy I don't think the per form thing is possible in this case. x-editable appends forms on the fly to allow editing of the area in concern. Additionally, according to the docs, csrf tokens are tied to the session and not the form, so having a valid csrf token in the ajax request is sufficient for Laravel to verify that it is not a bad request.

mehany left a reply on SSL LetsEncrypt Site Not Working On Forge • 2 years ago

I didnt use forge for a while now but I know that it could install letsencrypt for you without the need for a tutorial! https://laracasts.com/series/server-management-with-forge/episodes/12

anyways ssh to your server and run sudo nginx -t to check on the configurations, this should tell you what is wrong right away. then cd to /etc/nginx/sites-available and look into the server block for http and https, you should have something like the bellow

server {
  listen 80;
  server_name example.com www.example.com;
  # enforce https
  return 301 https://$server_name$request_uri;
  }

server {
  listen 443 ssl;
  server_name example.com www.example.com;
  root /home/forge/example.com/html/laravel/public;

  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

hope this helps

mehany left a reply on TokenMismatchException In VerifyCsrfToken.php • 2 years ago

No, you should just have one csrf token on the page and check the ajax params for the token, make sure it gets submitted

24th April, 2016

mehany left a reply on Why Dynamically Mounted Vue Components Does Not Appear In Devtool? • 2 years ago

@matiascx this is interesting! Have you tried posting this on Vue forums?

mehany left a reply on Login Form Using Auth • 2 years ago

@shanely scroll down a little bit in this class and you will see that username is supported already. You should just change the email field with username

23rd April, 2016

mehany left a reply on How To Parse A Laravel Log • 2 years ago

@Ackirb I just looked at this package and the source code seem to be a good place to get inspired.

I don't believe file_get_content was created for this purpose, you may like file instead - since php4

  // from PHP documentations
  $logFile = file(storage_path().'/logs/laravel-2016-04-24.log');
  $logCollection = [];
  // Loop through an array, show HTML source as HTML source; and line numbers too.
  foreach ($logFile as $line_num => $line) {
     $logCollection[] = array('line'=> $line_num, 'content'=> htmlspecialchars($line));
  }
  dd($logCollection);

22nd April, 2016

mehany left a reply on Do You Keep Models And Other Classes In The Same Namespace? • 2 years ago

@RoboRobok yeah I do. it helps reduce the size of the hugely expanded file structures. I have seen people leave it in the App namespace and I simply disagree with those. I create a folder with the domain name ( business name ) and I tend to keep every thing related to the business logic within this folder: models, repos, service providers ( singletons ), facades, you name it!

21st April, 2016

mehany left a reply on Is It Possible To Disable Cache On One View? • 2 years ago

@spekkionu that is correct, I just never looked into those cached file.

@premsaurav you were like hah "Where are the views being cached and how?" :)

mehany left a reply on Is It Possible To Disable Cache On One View? • 2 years ago

I believe views are cached in storage/framework/views by the framework. The content of the page in concern ( a cart page ) gets updated via Ajax requests from another view and sometimes it does not render the expected content. I am thinking this has to do with the caching mechanism that the framework does! or maybe with the way I render it! I use the cart facade in my view to render the content and I am thinking may be that gets cached! not sure what is the root cause though so I thought of asking if there is a way to disable caching on a specific view since the content of the cart may change during the same session.

mehany started a new conversation Is It Possible To Disable Cache On One View? • 2 years ago

I have one view that I don't ever want it to be cached, is there an easy way too achieve this?

17th April, 2016

mehany left a reply on Tokenmismatchexception Laravel 5.1 • 2 years ago

@umefarooq so tokenmismatchexception is thrown at all times!?

mehany left a reply on Zip PHP Extension Problem In Ubuntu (PHP7) • 2 years ago

The below should install zip extension on your Ubuntu server

 sudo apt-get install php7.0-zip 

Verify from any route with

 dd(get_loaded_extensions());

mehany left a reply on Gulp And Assets • 2 years ago

lol sorry but the time you spend trying to figure out why it is not copying is way more than doing it manually

15th April, 2016

mehany left a reply on Service Provider • 2 years ago

why a service provider for this! just add this on the top of your routes file!

 // For development purpose only
 DB::listen(function ($query) {
    \Log::info($query->sql);
 });

mehany left a reply on Blade And Angular Mixing • 2 years ago

@willvincent the OP is using a for loop

14th April, 2016

mehany left a reply on How To Use Blade @stack Syntax ? • 2 years ago

@mhankins obviously you have to be confused !! I was looking in the wrong view template that didn't call @push

mehany left a reply on How To Use Blade @stack Syntax ? • 2 years ago

@mhankins so how do you include the shared js?

mehany left a reply on How To Use Blade @stack Syntax ? • 2 years ago

@mhankins that didn't work! @Mubashar that is what I had before and didn't work.

mehany started a new conversation How To Use Blade @stack Syntax ? • 2 years ago

I have a template that shares a global js script that I include at the end of the main layout file. In some templates I want to use javascript on the same file and I want to append after the global js file.

  <body>

    @include('nav.header')

    @yield('content')

    @yield('sidebar')

    @include('scripts.globals') // this renders after, just before body tag

    @yield('scripts') // this renders before scripts.globals

</body>
  

mehany left a reply on How Increase Uploading File Size In Laravel. • 2 years ago

Try

   ini_set('memory_limit','256M');
   $file_name = $request->file('myImage');

mehany left a reply on Edited Vagrantfile In Hopes Of Getting My Shared Folers To Sync, Parse Error • 2 years ago

syntax error, unexpected end-of-input, expecting keyword_end[/quote] this error means your yaml file has unnecessary tabs or trailing spaces. Often people fall in that trap using a editor that automatically add these stuff. Use nano, vim, phpStorm, notepad++ I think all those editors won't adjust your yaml file on your behave.

13th April, 2016

mehany left a reply on Blade And Angular Mixing • 2 years ago

Try to change either one syntax to avoid conflict!

// example for blade 
Blade::setContentTags('<%', '%>'); // For variables.
Blade::setEscapedContentTags('<%%', '%%>'); // For escaped data.

or

var customInterpolationApp = angular.module('customInterpolationApp', []);

customInterpolationApp.config(function($interpolateProvider) {
   $interpolateProvider.startSymbol('{['); // or change it to something else
   $interpolateProvider.endSymbol(']}'); // or change it to something else
});

https://docs.angularjs.org/api/ng/provider/$interpolateProvider

mehany left a reply on Running Mix.version() Inside Gulp Task • 2 years ago

You can keep gulp tasks outside of Elixir and call gulp tasks inside the Elixir object like this

 elixir(function(mix) {
    mix.task('copyHtmlTemplates')
           .version([  /* files */ ])
    });

12th April, 2016

mehany left a reply on A Good Way To Handle FindOrFail Exception? • 2 years ago

so findOrFail return NotFoundHttpException , is there a clean way to handle this exception for a certain model and not all models? For instance in the User model, I would throw UserNotFoundException rather than just NotFoundHttpException . I don't like to wrap my code in try catch, although sometimes I am forced to do so! With try catch I can easily achieve that but correct me if I am wrong about not liking to use Try catch if you think that is a clean approach!

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.