RedBeanPHP\Facade::findOrCreate PHP Method

findOrCreate() public static method

If multiple beans match the criteria only the first one will be returned.
public static findOrCreate ( string $type, array $like = [] ) : OODBBean
$type string type of bean to search for
$like array criteria set describing the bean to search for
return OODBBean
    public static function findOrCreate($type, $like = array())
    {
        return self::$finder->findOrCreate($type, $like);
    }

Usage Example

Example #1
0
 /**
  * Tests the findOrCreate method.
  *
  * @return void
  */
 public function testFindOrCreate()
 {
     R::nuke();
     $book = R::findOrCreate('book', array('title' => 'my book', 'price' => 50));
     asrt($book instanceof OODBBean, TRUE);
     $id = $book->id;
     $book = R::findOrCreate('book', array('title' => 'my book', 'price' => 50));
     asrt($book->id, $id);
     asrt($book->title, 'my book');
     asrt((int) $book->price, 50);
 }