mardi 11 octobre 2016

MethodNotAllowedHttpException in RouteCollection.php in laravel 5.1

This is the code and I am working on form and when I submit the form, it shows this error:

MethodNotAllowedHttpException in RouteCollection.php line 218

Here is my code:

UserController.php

    <?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function postSignUp(Request $request){

        $email=$request['email'];
        $first_name=$request['first_name'];
        $password=bcrypt($request['password']);

        $user= new User();
        $user->email=$email;
        $user->first_name=$first_name;
        $user->password=$password;

        $user->save();
        return redirect()->back();

    }


}

routes.php

<?php


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

Route::post('/signup',[
        'uses' => 'UserController@postSignUp',
        'as' => 'signup'
    ]);

welcome.blade.php

@extends('layouts.master')

@section('title')
    Welcome!
@endsection

@section('content')
    <div class="row">
        <div class="col-md-6">
            <h3>Sign Up</h3>
            <form action="" mathod="post">
                <div class="form-group">
                   <label for="email">Email</label> 
                  <input type="email" class="form-control" name="email">
                </div>

                <div class="form-group">
                   <label for="first_name">Your First Name</label>  
                  <input type="text" class="form-control" name="first_name">
                </div>

                <div class="form-group">
                   <label for="password">Password</label>   
                  <input type="password" class="form-control" name="password">
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
                <input type="hidden" name="_token" value="">
            </form>

        </div>



    </div>
@endsection

Please note that I am working on laravel 5.1 & I am a beginner. Can you please help me to solve the problem?



via Chebli Mohamed

lundi 10 octobre 2016

Is it worth using entrust with Dingo API? Is there a better way?

I'm using Laravel 5 for my next project. I need to apply some role logic for the working. So here's what I've came up with:

$api = app('Dingo\Api\Routing\Router');

//admin routes!
$api->version('v1', ['middleware' => ['ability:admin,create-users']],
function ($api) {
$api->get('dingocheck', 'App\Http\Controllers\AdminController@index');
});

//store routes
$api->version('v1', ['middleware' => ['ability:store,create-products']],        
function ($api) {
$api->get('dingocheck', 'App\Http\Controllers\StoreController@index');
});

//userroutes
$api->version('v1', ['middleware' => ['ability:admin,puchase-products']],       
function ($api) {
$api->get('dingocheck', 'App\Http\Controllers\UserController@index'); });

I'm yet to resolve how to manage the modelling within the application. Thanks for help (:



via Chebli Mohamed

Laravel View [auth.login] not found after downloaded form bitbucket

My laravel project still online without any error, but when i downloaded my project form bitbucket to want to change something. it give me two error View [auth.login] not found.

and an another error bellow the first error failed to open stream: No such file or directory

i tried everything what i have on internet i tried composer-install composer clear-cache php artian clear-compiled but noting works for me.



via Chebli Mohamed

Accessing relationship of a relationship

I am adding in an announcements feature to my application.

I have an announcements table which stores the announcement and an announcement_active table which stores the undismissed announcements for each user.

When an announcement is created, a record is generated in the announcements table to store this and a record entered in to the announcement_active table for every user for that announcement.

My user model holds a relationship for the active announcements:

public function activeAnnouncements()
    {
        return $this->hasMany('App\ActiveAnnouncements');
    }

I am then accessing this in my view to check for any undismissed announcements like this:

@if (Auth::user()->activeAnnouncements()->count() > 0)
    //code
@endif

The above works fine, it is when I am trying to do a for each loop on the announcements that I am having trouble:

@if (Auth::user()->activeAnnouncements()->count() > 0)
    @foreach(Auth::user()->activeAnnouncements()->announcement as $announcement)
      //code to display announcement
   @endforeach
@endif

It is when I am chaining ->announcement that I run in to trouble. I have defined the relationship like so:

public function announcement()
    {
        return $this->belongsTo('\App\Announcements');
    }

However I get the error:

Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$announcement

When using Tinker and running \App\User::find(1)->activeAnnouncements()->first()->announcement the correct announcement shows.

Where am I going wrong when trying to load these in to my foreach loop?



via Chebli Mohamed

Laravel 5.1 File not deleting from folder

I want to delete a pdf file form my database as well as my public/uploads folder. It is deleting from the database but not from my public folder.

This is my controller:

 public function deleteArticle($id) {
    $article = Article::findOrFail($id);

     File::delete($article->document);
        $article->delete();
    return redirect()->back();
   }



via Chebli Mohamed

dimanche 9 octobre 2016

Laravel return a value if it is not unique

I am checking if the value is unique or not in the database using validation and here is the code:

 public function store(Request $request)
        {
            $select = 'select';

            //logged in user id
            $userid         = Auth::user() -> id;
            $usercountry    = Auth::user() -> country;

            $this -> validate($request, array(
                'number'        => 'required | unique:leads',
                'website'       => 'required | unique:leads',
                'lead_source'   => 'required | not_in:' . $select,
                'industry'      => 'required | not_in:' . $select,
                'action'        => 'required | not_in:' . $select
            ));
}

This works perfect but it show me a message telling me if the website input is duplicated or not.

What I am trying to do is to return a value from the table leads which contain the website column.

I found this code:

if ($validator->fails()) {
            $failedRules = $validator->failed();

        }

How I could modify it to return a value from the same duplicated row in the leads table?



via Chebli Mohamed

samedi 8 octobre 2016

Laravel - FatalErrorException in usahaController.php line 33: Call to a member function paginate() on a non-object

I am making a search page in Laravel and cant understand how to use the paginate method for this usage.

I have used it else where, but not like this. usahaController

    public function feindex()
{
    $hasil= DB::select('sELECT anggota.USERNAME, kategori_usaha.NAMA_KATEGORI_USAHA, usaha.NAMA_USAHA, 
        usaha.TYPE_UMKM, usaha.GAMBAR_UMUM, usaha.ALAMAT_USAHA, usaha.NOMOR_TLPN_USAHA FROM usaha 
        JOIN anggota on usaha.ID_ANGGOTA=anggota.ID_ANGGOTA 
        JOIN kategori_usaha on usaha.ID_KATEGORI_USAHA=kategori_usaha.ID_KATEGORI_USAHA')->paginate(2);
    $keranjang['usaha']=$hasil;  
    return view('feindex', $keranjang);

}

view

            @foreach ($usaha as $item)
        <div class="col-sm-6 col-md-3">
            <div class="thumbnail text-center">

                <a href="single_product.html"><img src="" class="img-responsive"></a>
                <br/>
                <h5 class="text-primary"></h5>
                <ul>
                    <li><i class="livicon" data-name="check" data-size="18" 
                    data-loop="true" data-c="#787878" data-hc="787878"></i> Nama Pengusaha :<br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</li>
                    <li><i class="livicon" data-name="check" data-size="18" 
                    data-loop="true" data-c="#787878" data-hc="787878"></i> </li>
                    <li><i class="livicon" data-name="check" data-size="18" 
                    data-loop="true" data-c="#787878" data-hc="787878"></i>  </li>
                    <li><i class="livicon" data-name="check" data-size="18" 
                    data-loop="true" data-c="#787878" data-hc="787878"></i> </li>
                    <li><i class="livicon" data-name="check" data-size="18" 
                    data-loop="true" data-c="#787878" data-hc="787878"></i>  </li>
                </ul>
                <a href="single_product.html" class="btn btn-primary btn-block text-white">View</a>
            </div>
        </div>
        @endforeach
        {!! $usaha->render() !!}

how fix this



via Chebli Mohamed