jeudi 27 juin 2019

Have another form and want to post for category in website

I have two form, In first form I have content, info, title, pic and columns category AND in another form I have name, category column.

First form of data is showing in website under menu and sub-menu.

Now I want to show the data of another form in sub-menu with id=13, and here is table image

post table https://ibb.co/s3bLMdg another table https://ibb.co/gPZ73Zz.

my view is for 2nd form like where i am storing the value of my id 13

        <div class="form-group table-dark text-white">
                                                               <input type="hidden" id="category" name="category_id" value="13">
                                                        </div>

but, still it' not showing on website



via Chebli Mohamed

Laravel 5.1 unexpected logout after redirect during login

I am working a personal project in Laravel 5.1 For some weird reason, I am not able to login.

When I submit the login form, no exception is thrown. I am automatically redirected to the home page and I am not logged in.

I have tried following remedies without any success as mentioned in here Laravel automatically logged out after few seconds?

  1. I have changed SESSION_DRIVER to database from file.
  2. I have changed the cookie value in config/session.php
  3. I have cleared the cashed and ran compose dump-autoload

I still have no success.



via Chebli Mohamed

How to fix: Duplicating path when using fopen on Laravel?

I'm using laravel 5.1, i'm trying to send a file that my Laravel application creates to an api, in a http request, the file was created in the right place on my application, but when i try to read this with fopen to append on the body of request, it gives the follow error:

fopen(/home/user/code/folder/application/storage//home/user/code/folder/application/storage/pdf/group/38/file.pdf): failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0):

I tried to use a laravel feature called "Storage" (https://laravel.com/docs/5.1/filesystem), but when i use that, i have unknown errors to send by a GuzzleHttpRequest, then it works when i using an existing path with fopen

The code that get the file to send is:

fopen(storage_path("{$doc->filepath}/{$doc->id}/{$doc->name}"), 'r');

It working when was like that:

fopen("../{$doc->filepath}/{$doc->id}/{$doc->name}"), 'r');

The path that i need to get is "/home/user/code/folder/application/storage/pdf/group/38/file.pdf"



via Chebli Mohamed

mercredi 26 juin 2019

How to write laravel 5.8 controllers routes similar to laravel 5.1

Having more than 20 controllers. It's very difficult to set each and every routes for add, edit and delete (also having more actions).

This is my laravel 5.1 routes.php :

Route::controllers([
  'user' => 'UserController',
  'taxes' => 'TaxController',
]);

Is there any way to support these routes in laravel 5.8?



via Chebli Mohamed

lundi 24 juin 2019

Laravel Multi-language Route Prefix

I managed to get some routes working with and without a prefix. Having routes that do not have the prefix work properly is important as it's too much work to go back and change all get/post links to the correct localized ones.

For example with the code below the url localhost/blog redirects to localhost/en/blog (or any other language stored in session).

However, I noticed that URLs with parameters dont work, so /blog/read/article-name will result in a 404 instead of redirecting to /en/blog/read/article-name.

Routes:

Route::group([
  'prefix' => '{locale}',
  'middleware' => 'locale'],
  function() {
  Route::get('blog', 'BlogController@index');
  Route::get('blog/read/{article_permalink}', 'BlogController@view');
  });

Middleware responsible for the redirects which doesnt seem to fire at all for some routes, as if the route group isn't matching the url.

    public function handle($request, Closure $next)
    {
      if ($request->method() === 'GET') {
          $segment = $request->segment(1);

          if (!in_array($segment, config('app.locales'))) {
              $segments = $request->segments();
              $fallback = session('locale') ?: config('app.fallback_locale');
              $segments = array_prepend($segments, $fallback);

              return redirect()->to(implode('/', $segments));
          }

          session(['locale' => $segment]);
          app()->setLocale($segment);
      }

      return $next($request);
    }



via Chebli Mohamed

mercredi 19 juin 2019

vendredi 14 juin 2019

Laravel custom validation to all model

I am using laravel latest version and i have a common field in all model called slug.I would to check whether slug is unique or not. i have slug field in all tables

so i have extended Valdiator class

class CustomValidator extends Validator{

protected function validateIsUniqueSlug($attribute, $value, $parameters)
    {

        $isSlugExist= User::where('slug', $value)->exists();
        if ($isSlugExist) {
            return false;
        }
        return true;
    }

}

this works but problem here is i need to repeat this for models but i dont want to do this .is there any better approach so i can handle it in one method

i know laravel has sluggable package but for some reason i cant use that package



via Chebli Mohamed