1

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class mypage extends Model
{
   public $rules = [
    'name' => 'required',
    'message' => 'required',
    'password' => 'required'
   ];

   public $edit = [
    'message' => 'required'
   ];

   protected $table = 'mypages';
}

I want to use on controller like this , $validator = validator::make($data = Input::all(), mypage::$edit);, $validator = validator::make($data = Input::all(), mypage::$rules);

but It brings error like this:FatalThrowableError in MyPageController.php line 59: Access to undeclared static property: App\mypage::$edit

How can I use like this?

8
  • try using $this->edit Commented Nov 18, 2016 at 7:13
  • declare $rules and $edit as static like, public static $rules and public static $edit Commented Nov 18, 2016 at 7:15
  • @kapil.dev not working too Commented Nov 18, 2016 at 7:22
  • @LalitThapa then It brings error like:MassAssignmentException in Model.php line 452: mypage Commented Nov 18, 2016 at 7:25
  • 1
    Not exactly. At first write $mypage = new mypage(); then you don't need to do $validator = Validator::make($data = Input::all(), mypage::$mypage->rules), you can just write $validator = Validator::make(Input::all(), $mypage->rules) Commented Nov 18, 2016 at 7:41

1 Answer 1

2

Try to use static keyword:

public static $edit = [
    'message' => 'required'
];
Sign up to request clarification or add additional context in comments.

2 Comments

I declare like public static $rules and public static $edit, then It brings error like: MassAssignmentException in Model.php line 452: mypage
You get MassAssignmentException because you didn't add $fillable array to your model, not because of using static.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.